Skip to content
Snippets Groups Projects
Commit ac045fe4 authored by Jason A. Donenfeld's avatar Jason A. Donenfeld
Browse files

Abstract remove empty directories into function.

parent b5f828c8
No related branches found
No related tags found
No related merge requests found
...@@ -29,9 +29,9 @@ git_add_file() { ...@@ -29,9 +29,9 @@ git_add_file() {
git_commit "$2" git_commit "$2"
} }
git_commit() { git_commit() {
local sign local sign=""
[[ -d $GIT_DIR ]] || return [[ -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" git commit $sign -m "$1"
} }
yesno() { yesno() {
...@@ -114,6 +114,12 @@ reencrypt_path() { ...@@ -114,6 +114,12 @@ reencrypt_path() {
prev_gpg_recipients="${GPG_RECIPIENTS[@]}" prev_gpg_recipients="${GPG_RECIPIENTS[@]}"
done done
} }
remove_empty_directories() {
local old_dir="$1"
while rmdir "$old_dir" &>/dev/null; do
old_dir="${old_dir%/*}"
done
}
# #
# END helper functions # END helper functions
...@@ -275,10 +281,7 @@ cmd_init() { ...@@ -275,10 +281,7 @@ cmd_init() {
git rm -qr "$gpg_id" git rm -qr "$gpg_id"
git_commit "Deinitialized ${gpg_id}." git_commit "Deinitialized ${gpg_id}."
fi fi
gpg_id="${gpg_id%/*}" remove_empty_directories "${gpg_id%/*}"
while rmdir "$gpg_id" &>/dev/null; do
gpg_id="${gpg_id%/*}"
done
exit 0 exit 0
fi fi
...@@ -542,10 +545,7 @@ cmd_delete() { ...@@ -542,10 +545,7 @@ cmd_delete() {
git rm -qr "$passfile" git rm -qr "$passfile"
git_commit "Removed $path from store." git_commit "Removed $path from store."
fi fi
passfile="${passfile%/*}" remove_empty_directories "${passfile%/*}"
while rmdir "$passfile" &>/dev/null; do
passfile="${passfile%/*}"
done
} }
cmd_copy_move() { cmd_copy_move() {
...@@ -593,10 +593,7 @@ cmd_copy_move() { ...@@ -593,10 +593,7 @@ cmd_copy_move() {
git rm -qr "$old_path" git rm -qr "$old_path"
git_add_file "$new_path" "Renamed ${1} to ${2}." git_add_file "$new_path" "Renamed ${1} to ${2}."
fi fi
remove_empty_directories "$old_dir"
while rmdir "$old_dir" &>/dev/null; do
old_dir="${old_dir%/*}"
done
else else
cp $interactive -r -v "$old_path" "$new_path" || exit 1 cp $interactive -r -v "$old_path" "$new_path" || exit 1
[[ -e "$new_path" ]] && reencrypt_path "$new_path" [[ -e "$new_path" ]] && reencrypt_path "$new_path"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment