[pass] [PATCH 2/2] Don't overwrite on generate (unless -f supplied)
Brian Mattern
rephorm at rephorm.com
Thu Sep 20 07:27:10 CEST 2012
---
src/password-store.sh | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/password-store.sh b/src/password-store.sh
index 0cbff15..b8336e9 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -43,9 +43,10 @@ Usage:
before overwriting existing password unless forced.
$program edit pass-name
Insert a new password or edit an existing password using ${EDITOR:-vi}.
- $program generate [--no-symbols,-n] [--clip,-c] pass-name pass-length
+ $program generate [--no-symbols,-n] [--clip,-c] [--force,-f] pass-name pass-length
Generate a new password of pass-length with optionally no symbols.
Optionally put it on the clipboard and clear board after 45 seconds.
+ Prompt before overwriting existing password unless forced.
$program rm [--recursive,-r] [--force,-f] pass-name
Remove existing password or directory, optionally forcefully.
$program git git-command-args...
@@ -290,13 +291,15 @@ case "$command" in
clip=0
symbols="-y"
+ force=0
- opts="$($GETOPT -o nc -l no-symbols,clip -n "$program" -- "$@")"
+ opts="$($GETOPT -o ncf -l no-symbols,clip,force -n "$program" -- "$@")"
err=$?
eval set -- "$opts"
while true; do case $1 in
-n|--no-symbols) symbols=""; shift ;;
-c|--clip) clip=1; shift ;;
+ -f|--force) force=1; shift ;;
--) shift; break ;;
esac done
@@ -313,6 +316,13 @@ case "$command" in
mkdir -p -v "$PREFIX/$(dirname "$path")"
pass="$($PWGEN -s $symbols $length 1)"
passfile="$PREFIX/$path.gpg"
+
+ if [[ $force -eq 0 && -e $passfile ]]; then
+ prompt="An entry already exists for $path. Overwrite it [y/N]? "
+ read -p "$prompt" yesno
+ [[ $yesno == "y" || $yesno == "Y" ]] || exit 1
+ fi
+
$GPG -e -r "$ID" -o "$passfile" $GPG_OPTS <<<"$pass"
git_add_file "$passfile" "Added generated password for $path to store."
--
1.7.9.5
More information about the Password-Store
mailing list