From be00f92abf19f94fd2c11b249e84dc39d4cbfc98 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 7 Sep 2025 18:54:55 +0100 Subject: [PATCH] Delete zets by title --- zet | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/zet b/zet index f6bbd1c..9c77f48 100755 --- a/zet +++ b/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 - exit 1 + 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() {