Delete zets by title
This commit is contained in:
parent
7d5e9028a9
commit
be00f92abf
1 changed files with 24 additions and 10 deletions
34
zet
34
zet
|
@ -38,24 +38,38 @@ commit_changes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_zet() {
|
delete_zet() {
|
||||||
# TODO: delete zets by title.
|
query="$1"
|
||||||
|
|
||||||
id="$1"
|
file="${ZET_DIR}/${query}/index.adoc"
|
||||||
dir="${ZET_DIR}/${id}"
|
|
||||||
|
|
||||||
if [[ -d "$dir" ]]; then
|
if [[ -f "$file" ]]; then
|
||||||
mv -v "$dir" "/tmp/zet-${id}"
|
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}"
|
git -C "$ZET_DIR" commit -m "$commit_message"
|
||||||
run_git_command commit -m "$commit_message"
|
|
||||||
|
|
||||||
update_zet_list
|
update_zet_list
|
||||||
else
|
else
|
||||||
echo "Note not found: $id" >&2
|
result="$(search_zets "$query")"
|
||||||
exit 1
|
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
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_zet() {
|
edit_zet() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue