Delete zets by title
This commit is contained in:
parent
7d5e9028a9
commit
be00f92abf
1 changed files with 24 additions and 10 deletions
32
zet
32
zet
|
@ -38,24 +38,38 @@ commit_changes() {
|
|||
}
|
||||
|
||||
delete_zet() {
|
||||
# TODO: delete zets by title.
|
||||
query="$1"
|
||||
|
||||
id="$1"
|
||||
dir="${ZET_DIR}/${id}"
|
||||
file="${ZET_DIR}/${query}/index.adoc"
|
||||
|
||||
if [[ -d "$dir" ]]; then
|
||||
mv -v "$dir" "/tmp/zet-${id}"
|
||||
if [[ -f "$file" ]]; then
|
||||
run_git_command rm -rf "$file"
|
||||
|
||||
run_git_command rm -r "$dir"
|
||||
commit_message="Delete $file"
|
||||
commit_message="${commit_message//$ZET_DIR\//}"
|
||||
commit_message="${commit_message//\/index.adoc/}"
|
||||
|
||||
commit_message="Delete ${id}"
|
||||
run_git_command commit -m "$commit_message"
|
||||
git -C "$ZET_DIR" commit -m "$commit_message"
|
||||
|
||||
update_zet_list
|
||||
else
|
||||
echo "Note not found: $id" >&2
|
||||
result="$(search_zets "$query")"
|
||||
result_count="$(echo "$result" | grep -c '^')"
|
||||
|
||||
if [[ "$result_count" -eq 0 ]]; then
|
||||
echo "No results found for query: $query" >&2
|
||||
exit 1
|
||||
elif [[ "$result_count" -eq 1 ]]; then
|
||||
id="$(echo "$result" | awk '{print $1}')"
|
||||
else
|
||||
selected="$(echo "$result" | sort | fzf)" || exit 0
|
||||
|
||||
id="$(echo "$selected" | awk '{print $1}')"
|
||||
fi
|
||||
|
||||
delete_zet "$id"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
edit_zet() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue