[pass] [PATCH 1/5] Confirm before overwriting an entry

Brian Mattern rephorm at rephorm.com
Thu Sep 13 07:24:11 CEST 2012


This asks before inserting a password when one already exists at that
location (instead of just overwriting it).

---
 src/password-store.sh |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 12ef62b..ad8f8ce 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -184,9 +184,21 @@ case "$command" in
 			exit 1
 		fi
 		path="$1"
+		passfile="$PREFIX/$path.gpg"
+
+		if [[ -e $passfile ]]; then
+			prompt="An entry already exists at '$path'. Overwrite it (y/n)? "
+			read -p "$prompt" -s -n 1 overwrite
+
+			if [[ $overwrite != 'y' ]]; then
+				echo -e "\nCancelling."
+				exit
+			fi
+			echo
+		fi
+
 		mkdir -p -v "$PREFIX/$(dirname "$path")"
 
-		passfile="$PREFIX/$path.gpg"
 		if [[ $ml -eq 1 ]]; then
 			echo "Enter contents of $path and press Ctrl+D when finished:"
 			echo
-- 
1.7.9.5





More information about the Password-Store mailing list