[pass] [PATCH] Add move option

Laurent Navet laurent.navet at gmail.com
Mon Apr 15 22:01:37 CEST 2013


Allow to move and rearrange branches in password tree

Signed-off-by: Laurent Navet <laurent.navet at gmail.com>
---
 src/password-store.sh |   43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 99010e9..2cad6a4 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -42,6 +42,8 @@ Usage:
         Insert new password. Optionally, the console can be enabled echo
         the password back. Or, optionally, it may be multiline. Prompt
         before overwriting existing password unless forced.
+    $program move [--force,-f] old-pass-name new-pass-name
+        Allow to move and rearrange branches
     $program edit pass-name
         Insert a new password or edit an existing password using ${EDITOR:-vi}.
     $program generate [--no-symbols,-n] [--clip,-c] [--force,-f] pass-name pass-length
@@ -63,7 +65,7 @@ _EOF
 }
 is_command() {
 	case "$1" in
-		init|ls|list|show|insert|edit|generate|remove|rm|delete|git|help|--help|version|--version) return 0 ;;
+		init|ls|list|show|insert|move|edit|generate|remove|rm|delete|git|help|--help|version|--version) return 0 ;;
 		*) return 1 ;;
 	esac
 }
@@ -278,6 +280,45 @@ case "$command" in
 		fi
 		git_add_file "$passfile" "Added given password for $path to store."
 		;;
+        move)
+                force=0
+                opts="$($GETOPT -o f -l force -n "$program" -- "$@")"
+                err=$?
+                eval set -- "$opts"
+                while true; do case $1 in
+                        -f|--force) force=1; shift ;;
+                        --) shift; break ;;
+                esac done
+
+                if [[ $# -ne 2 ]]; then
+                        echo "Usage: $program $command [--force,-f] old-pass-name new-pass-name"
+                        exit 1
+                fi
+
+                oldpath="$1"
+                newpath="$2"
+                oldpassfile="$PREFIX/${oldpath%/}"
+                newpassfile="$PREFIX/${newpath%/}"
+
+                if [[ ! -d $oldpassfile ]]; then
+                        oldpassfile="$PREFIX/$oldpath.gpg"
+                        if [[ ! -f $oldpassfile ]]; then
+                                echo "$oldpath is not in the password store."
+                                exit 1
+                        else
+                                newpassfile="$PREFIX/$newpath.gpg"
+                        fi
+                fi
+
+                [[ $force -eq 1 ]] || yesno "Are you sure you would like to move $oldpath to $newpath ?"
+
+                mv -f -v $oldpassfile $newpassfile
+                if [[ -d $GIT_DIR &&  -e $newpassfile ]]; then
+                        git rm -qr "$oldpassfile"
+                        git_add_file "$newpassfile" "Moved $oldpassfile to $newpassfile."
+                        git commit -m "Moved $oldpath to $newpath."
+                fi
+                ;;
 	edit)
 		if [[ $# -ne 1 ]]; then
 			echo "Usage: $program $command pass-name"
-- 
1.7.10.4




More information about the Password-Store mailing list