diff options
-rw-r--r-- | man/pass.1 | 24 | ||||
-rwxr-xr-x | src/password-store.sh | 46 |
2 files changed, 28 insertions, 42 deletions
@@ -104,14 +104,6 @@ alternatively named \fBremove\fP or \fBdelete\fP. If \fI--recursive\fP or \fI-r\ is specified, delete pass-name recursively if it is a directory. If \fI--force\fP or \fI-f\fP is specified, do not interactively prompt before removal. .TP -\fBpush\fP -If the password store is a git repository, push the latest changes using -.BR git-push (1). -.TP -\fBpull\fP -If the password store is a git repository, pull the latest changes using -.BR git-pull (1). -.TP \fBgit\fP \fIgit-command-args\fP... If the password store is a git repository, pass \fIgit-command-args\fP as arguments to .BR git (1) @@ -223,7 +215,7 @@ rm: remove regular file \[u2018]/home/zx2c4/.password-store/Business/cheese-whiz removed \[u2018]/home/zx2c4/.password-store/Business/cheese-whiz-factory.gpg\[u2019] .SH EXTENDED GIT EXAMPLE -Here, we initialize new password store, create a git repository, and then manipulate and sync passwords. Make note of the arguments to the first call of \fBpass push\fP; consult +Here, we initialize new password store, create a git repository, and then manipulate and sync passwords. Make note of the arguments to the first call of \fBpass git push\fP; consult .BR git-push (1) for more information. @@ -235,7 +227,13 @@ Password store initialized for Jason@zx2c4.com. .B zx2c4@laptop ~ $ pass git init .br -Initialized empty Git repository in /home/zx2c4/.password-store/.git/ +Initialized empty Git repository in /home/zx2c4/.password-store/.git/ +.br +[master (root-commit) 998c8fd] Added current contents of password store. +.br + 1 file changed, 1 insertion(+) +.br + create mode 100644 .gpg-id .B zx2c4@laptop ~ $ pass git remote add origin kexec.com:pass-store @@ -243,7 +241,7 @@ Initialized empty Git repository in /home/zx2c4/.password-store/.git/ .br mkdir: created directory \[u2018]/home/zx2c4/.password-store/Amazon\[u2019] .br -[master (root-commit) 30fdc1e] Added generated password for Amazon/amazonemail@email.com to store. +[master 30fdc1e] Added generated password for Amazon/amazonemail@email.com to store. .br 1 file changed, 0 insertions(+), 0 deletions(-) .br @@ -253,7 +251,7 @@ The generated password to Amazon/amazonemail@email.com is: .br <5m,_BrZY`antNDxKN<0A -.B zx2c4@laptop ~ $ pass push -u --all +.B zx2c4@laptop ~ $ pass git push -u --all .br Counting objects: 4, done. .br @@ -295,7 +293,7 @@ rm 'Amazon/amazonemail@email.com.gpg' .br delete mode 100644 Amazon/amazonemail@email.com.gpg -.B zx2c4@laptop ~ $ pass push +.B zx2c4@laptop ~ $ pass git push .br Counting objects: 9, done. .br diff --git a/src/password-store.sh b/src/password-store.sh index 411f467..1960636 100755 --- a/src/password-store.sh +++ b/src/password-store.sh @@ -48,10 +48,6 @@ Usage: Optionally put it on the clipboard and clear board after 45 seconds. $program rm [--recursive,-r] [--force,-f] pass-name Remove existing password or directory, optionally forcefully. - $program push - If the password store is a git repository, push the latest changes. - $program pull - If the password store is a git repository, pull the latest changes. $program git git-command-args... If the password store is a git repository, execute a git command specified by git-command-args. @@ -61,9 +57,9 @@ Usage: Show version information. _EOF } -isCommand() { +is_command() { case "$1" in - init|ls|list|show|insert|edit|generate|remove|rm|delete|push|pull|git|help|--help|version|--version) return 0 ;; + init|ls|list|show|insert|edit|generate|remove|rm|delete|git|help|--help|version|--version) return 0 ;; *) return 1 ;; esac } @@ -115,10 +111,16 @@ GETOPT="getopt" # END Platform definable # +function git_add_file() { + [[ -d $GIT_DIR ]] || return + git add "$1" || return + [[ -n $(git status --porcelain "$1") ]] || return + git commit -m "$2" +} program="$(basename "$0")" command="$1" -if isCommand "$command"; then +if is_command "$command"; then shift else command="show" @@ -134,6 +136,7 @@ case "$command" in mkdir -v -p "$PREFIX" echo "$gpg_id" > "$ID" echo "Password store initialized for $gpg_id." + git_add_file "$ID" "Set GPG id to $gpg_id." exit 0 ;; help|--help) @@ -246,10 +249,7 @@ case "$command" in read -p "Enter password for $path: " -e password $GPG -e -r "$ID" -o "$passfile" $GPG_OPTS <<<"$password" fi - if [[ -d $GIT_DIR ]]; then - git add "$passfile" - git commit -m "Added given password for $path to store." - fi + git_add_file "$passfile" "Added given password for $path to store." ;; edit) if [[ $# -ne 1 ]]; then @@ -277,11 +277,7 @@ case "$command" in echo "GPG encryption failed. Retrying." sleep 1 done - - if [[ -d $GIT_DIR ]]; then - git add "$passfile" - git commit -m "$action password for $path using ${EDITOR:-vi}." - fi + git_add_file "$passfile" "$action password for $path using ${EDITOR:-vi}." ;; generate) clip=0 @@ -310,10 +306,7 @@ case "$command" in pass="$(pwgen -s $symbols $length 1)" passfile="$PREFIX/$path.gpg" $GPG -e -r "$ID" -o "$passfile" $GPG_OPTS <<<"$pass" - if [[ -d $GIT_DIR ]]; then - git add "$passfile" - git commit -m "Added generated password for $path to store." - fi + git_add_file "$passfile" "Added generated password for $path to store." if [ $clip -eq 0 ]; then echo "The generated password to $path is:" @@ -353,16 +346,11 @@ case "$command" in git commit -m "Removed $path from store." fi ;; - push|pull) - if [[ -d $GIT_DIR ]]; then - exec git $command "$@" - else - echo "Error: the password store is not a git repository." - exit 1 - fi - ;; git) - if [[ $1 == "init" || -d $GIT_DIR ]]; then + if [[ $1 == "init" ]]; then + git "$@" || exit 1 + git_add_file "$PREFIX" "Added current contents of password store." + elif [[ -d $GIT_DIR ]]; then exec git "$@" else echo "Error: the password store is not a git repository." |