m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2014-04-18 12:48:55 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2014-04-18 12:48:55 +0200
commitac045fe4254306fbcc32ffce058b860d5a473b98 (patch)
tree0a9200f08609b5246ed52e7fae4b9c2e9a451787
parentb5f828c87e7074c6bb52ac243ac19b735419b5ac (diff)
Abstract remove empty directories into function.
-rwxr-xr-xsrc/password-store.sh25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/password-store.sh b/src/password-store.sh
index a3fd640..572ce2a 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -29,9 +29,9 @@ git_add_file() {
git_commit "$2"
}
git_commit() {
- local sign
+ local sign=""
[[ -d $GIT_DIR ]] || return
- [[ $(git config --bool --get pass.signcommits) == "true" ]] && sign="-S" || sign=""
+ [[ $(git config --bool --get pass.signcommits) == "true" ]] && sign="-S"
git commit $sign -m "$1"
}
yesno() {
@@ -114,6 +114,12 @@ reencrypt_path() {
prev_gpg_recipients="${GPG_RECIPIENTS[@]}"
done
}
+remove_empty_directories() {
+ local old_dir="$1"
+ while rmdir "$old_dir" &>/dev/null; do
+ old_dir="${old_dir%/*}"
+ done
+}
#
# END helper functions
@@ -275,10 +281,7 @@ cmd_init() {
git rm -qr "$gpg_id"
git_commit "Deinitialized ${gpg_id}."
fi
- gpg_id="${gpg_id%/*}"
- while rmdir "$gpg_id" &>/dev/null; do
- gpg_id="${gpg_id%/*}"
- done
+ remove_empty_directories "${gpg_id%/*}"
exit 0
fi
@@ -542,10 +545,7 @@ cmd_delete() {
git rm -qr "$passfile"
git_commit "Removed $path from store."
fi
- passfile="${passfile%/*}"
- while rmdir "$passfile" &>/dev/null; do
- passfile="${passfile%/*}"
- done
+ remove_empty_directories "${passfile%/*}"
}
cmd_copy_move() {
@@ -593,10 +593,7 @@ cmd_copy_move() {
git rm -qr "$old_path"
git_add_file "$new_path" "Renamed ${1} to ${2}."
fi
-
- while rmdir "$old_dir" &>/dev/null; do
- old_dir="${old_dir%/*}"
- done
+ remove_empty_directories "$old_dir"
else
cp $interactive -r -v "$old_path" "$new_path" || exit 1
[[ -e "$new_path" ]] && reencrypt_path "$new_path"