Support for multiple arguments to rm & dev questions

janek 27jf at protonmail.com
Fri Dec 18 18:44:48 CET 2020


Hey,

I was trying to use the pass rm command like my normal rm command, with multiple args, and it failed. The patch below makes it work.

While developing, two questions sprung into my mind:
1. You get the directory of the file via "${passfile%/*}" - isn't "dirname" the appropriate solution?
2. Why do you use double brackets where single brackets i.e. the test command would suffice?

Regards,
Xerus

diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..7908ed8 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -570,26 +570,29 @@ cmd_delete() {
               -f|--force) force=1; shift ;;
               --) shift; break ;;
       esac done
-       [[ $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND [--recursive,-r] [--force,-f] pass-name"
-       local path="$1"
-       check_sneaky_paths "$path"
-
-       local passdir="$PREFIX/${path%/}"
-       local passfile="$PREFIX/$path.gpg"
-       [[ -f $passfile && -d $passdir && $path == */ || ! -f $passfile ]] && passfile="${passdir%/}/"
-       [[ -e $passfile ]] || die "Error: $path is not in the password store."
-       set_git "$passfile"
+ test $# -eq 0 && die "Usage: $PROGRAM $COMMAND [--recursive,-r] [--force,-f] pass-name..."
+ while test -n "$1"; do
+ local path="$1"
+ check_sneaky_paths "$path"
+
+ local passdir="$PREFIX/${path%/}"
+ local passfile="$PREFIX/$path.gpg"
+ [[ -f $passfile && -d $passdir && $path == */ || ! -f $passfile ]] && passfile="${passdir%/}/"
+ [[ -e $passfile ]] || die "Error: $path is not in the password store."
+ set_git "$passfile"
 
-       [[ $force -eq 1 ]] || yesno "Are you sure you would like to delete $path?"
+ [[ $force -eq 1 ]] || yesno "Are you sure you would like to delete $path?"
 
-       rm $recursive -f -v "$passfile"
-       set_git "$passfile"
-       if [[ -n $INNER_GIT_DIR && ! -e $passfile ]]; then
-               git -C "$INNER_GIT_DIR" rm -qr "$passfile"
+ rm $recursive -f -v "$passfile"
               set_git "$passfile"
-               git_commit "Remove $path from store."
-       fi
-       rmdir -p "${passfile%/*}" 2>/dev/null
+ if [[ -n $INNER_GIT_DIR && ! -e $passfile ]]; then
+ git -C "$INNER_GIT_DIR" rm -qr "$passfile"
+ set_git "$passfile"
+ git_commit "Remove $path from store."
+ fi
+ rmdir -p "${passfile%/*}" 2>/dev/null
+ shift
+ done
}


More information about the Password-Store mailing list