m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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."