summaryrefslogtreecommitdiff
path: root/src/password-store.sh
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-09-19 04:24:43 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2012-09-19 04:24:43 +0200
commit579db9ca9c5a3d8ee60fc15d2be609775827d436 (patch)
tree78d6d176629d099d85135f1dfca4da513b686932 /src/password-store.sh
parentc5aaa008d6a39d4cb016847eaf176584209b1ac6 (diff)
downloadpass-579db9ca9c5a3d8ee60fc15d2be609775827d436.tar.gz
pass-579db9ca9c5a3d8ee60fc15d2be609775827d436.tar.bz2
pass-579db9ca9c5a3d8ee60fc15d2be609775827d436.zip
Clean up git handling.
Get rid of push/pull shortcuts, as they weren't widely used. Add contents to repo on git init. Centralize git add logic, and make it less error prone.
Diffstat (limited to 'src/password-store.sh')
-rwxr-xr-xsrc/password-store.sh46
1 files changed, 17 insertions, 29 deletions
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."