[pass] [PATCH] Added 'rename' command
Matthieu Weber
mweber at free.fr
Mon Aug 12 20:08:06 CEST 2013
---
contrib/pass.bash-completion | 4 +++
contrib/pass.fish-completion | 4 +++
contrib/pass.zsh-completion | 7 ++++++
src/password-store.sh | 50 +++++++++++++++++++++++++++++++++++++++++-
4 files changed, 64 insertions(+), 1 deletions(-)
diff --git a/contrib/pass.bash-completion b/contrib/pass.bash-completion
index d0ef012..26cde8d 100644
--- a/contrib/pass.bash-completion
+++ b/contrib/pass.bash-completion
@@ -70,6 +70,10 @@ _pass()
COMPREPLY+=($(compgen -W "-n --no-symbols -c --clip -f --force" -- ${cur}))
_pass_complete_entries
;;
+ mv|rename)
+ COMPREPLY+=($(compgen -W "-f --force" -- ${cur}))
+ _pass_complete_entries
+ ;;
rm|remove|delete)
COMPREPLY+=($(compgen -W "-r --recursive -f --force" -- ${cur}))
_pass_complete_entries
diff --git a/contrib/pass.fish-completion b/contrib/pass.fish-completion
index 9130d1f..6f0e20e 100644
--- a/contrib/pass.fish-completion
+++ b/contrib/pass.fish-completion
@@ -80,6 +80,10 @@ complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s c -l clip -d '
complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s f -l force -d 'Do not prompt before overwritting'
complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -a "(__fish_pass_print_entry_dirs)"
+complete -c $PROG -f -A -n '__fish_pass_needs_command' -a mv -d 'Command: rename existing password'
+complete -c $PROG -f -A -n '__fish_pass_uses_command mv' -s f -l force -d 'Force rename'
+complete -c $PROG -f -A -n '__fish_pass_uses_command mv' -a "(__fish_pass_print_entries_and_dirs)"
+
complete -c $PROG -f -A -n '__fish_pass_needs_command' -a rm -d 'Command: remove existing password'
complete -c $PROG -f -A -n '__fish_pass_uses_command rm' -s r -l recursive -d 'Remove password groups recursively'
complete -c $PROG -f -A -n '__fish_pass_uses_command rm' -s f -l force -d 'Force removal'
diff --git a/contrib/pass.zsh-completion b/contrib/pass.zsh-completion
index 848bc67..7f42d15 100644
--- a/contrib/pass.zsh-completion
+++ b/contrib/pass.zsh-completion
@@ -43,6 +43,12 @@ _pass () {
"--clip[copy password to the clipboard]"
_pass_complete_entries_with_subdirs
;;
+ mv|rename)
+ _arguments : \
+ "-f[force rename]" \
+ "--force[force rename]" \
+ _pass_complete_entries_with_subdirs
+ ;;
rm)
_arguments : \
"-f[force deletion]" \
@@ -76,6 +82,7 @@ _pass () {
"insert:Insert a new password"
"generate:Generate a new password using pwgen"
"edit:Edit a password with \$EDITOR"
+ "mv:Rename the password"
"rm:Remove the password"
"git:Call git on the password store"
"version:Output version information"
diff --git a/src/password-store.sh b/src/password-store.sh
index e080627..df24025 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -48,6 +48,9 @@ Usage:
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 mv [--force,-f] old-pass-name new-pass-name
+ Rename old-pass-name to new-pass-name.
+ Prompt before renaming unless forced.
$program rm [--recursive,-r] [--force,-f] pass-name
Remove existing password or directory, optionally forcefully.
$program git git-command-args...
@@ -63,7 +66,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|edit|generate|rename|mv|remove|rm|delete|git|help|--help|version|--version) return 0 ;;
*) return 1 ;;
esac
}
@@ -347,6 +350,51 @@ case "$command" in
clip "$pass" "$path"
fi
;;
+ rename|mv)
+ 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
+ old_path="$1"
+ new_path="$2"
+ old_passfile="$PREFIX/${old_path%/}"
+ if [[ ! -d $old_passfile ]]; then
+ old_passfile="$PREFIX/$old_path.gpg"
+ if [[ ! -f $old_passfile ]]; then
+ echo "$old_path is not in the password store."
+ exit 1
+ fi
+ fi
+ new_passfile="$PREFIX/${new_path%/}"
+ if [[ -d $new_passfile ]]; then
+ echo "Destination cannot be a directory, specify the destination filename as well."
+ exit 1
+ fi
+ new_passfile="$PREFIX/$new_path.gpg"
+ if [[ -e $new_passfile ]]; then
+ echo "$new_path is already in the password store."
+ exit 1
+ fi
+ [[ $force -eq 1 ]] || yesno "Are you sure you would like to rename $old_path to $new_path?"
+ mkdir -p -v "$PREFIX/$(dirname "$new_path")"
+
+ if [[ -e $old_passfile && ! -e $new_passfile ]]; then
+ if [[ -d $GIT_DIR ]]; then
+ git mv "$old_passfile" "$new_passfile"
+ git commit -m "Renamed $old_path to $new_path."
+ else
+ mv -v "$old_passfile" "$new_passfile"
+ fi
+ fi
+ ;;
delete|rm|remove)
recursive=""
force=0
--
1.7.2.5
More information about the Password-Store
mailing list