From 2a250daa34d395697c97eaddf9fd24fae647f0e8 Mon Sep 17 00:00:00 2001 From: thek4n Date: Tue, 5 Nov 2024 12:23:56 +0300 Subject: [PATCH] t script feature remove multiple notes --- home/user/.local/bin/t | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/home/user/.local/bin/t b/home/user/.local/bin/t index 5ebba5a..31b8a61 100755 --- a/home/user/.local/bin/t +++ b/home/user/.local/bin/t @@ -21,13 +21,13 @@ cmd_help() { echo "USAGE T script for fast notes - t - Show notes in format '[INDEX] NOTE NAME (LINES)' - t show - Show notes in format '[INDEX] NOTE NAME (LINES)' - t namespaces - Show namespaces - t add (X X X) - Add note with name X X X - t edit (INDEX) - Edit note with INDEX by \$EDITOR - t delete (INDEX) - Delete note with INDEX - t --help - Show this message + t - Show notes in format '[INDEX] NOTE NAME (LINES)' + t show - Show notes in format '[INDEX] NOTE NAME (LINES)' + t namespaces - Show namespaces + t add (X X X) - Add note with name X X X + t edit (INDEX) - Edit note with INDEX by \$EDITOR + t delete (INDEX) [INDEX] ... - Delete notes with INDEXes + t --help - Show this message t a - alias to add t e - alias to edit @@ -68,7 +68,7 @@ _remove_first_and_last_element() { find_note_name_by_index() { note_index="${1}" - show_notes_with_indexes | grep "^\[${note_index}\]" | _remove_first_and_last_element + grep "^\[${note_index}\]" | _remove_first_and_last_element } cmd_add_note() { @@ -78,21 +78,27 @@ cmd_add_note() { } cmd_delete_note() { - note_index="${1}" - note="$(find_note_name_by_index "${note_index}")" - note_to_remove="${NOTES_DIR}/${note}" + current_notes="$(show_notes_with_indexes)" + + for note_index in "$@" + do + note="$(echo "${current_notes}" | find_note_name_by_index "${note_index}")" + note_to_remove="${NOTES_DIR}/${note}" + + if [ ! -f "${note_to_remove}" ]; then + die "Note with index ${note_index} not found" 1 + fi + + rm "${note_to_remove}" + done - if [ ! -f "${note_to_remove}" ]; then - die "Note with index ${note_index} not found" 1 - fi - rm "${note_to_remove}" exit "$EXIT_SUCCESS" } cmd_edit_note() { note_index="${1}" - note="$(find_note_name_by_index "${note_index}")" + note="$(show_notes_with_indexes | find_note_name_by_index "${note_index}")" note_to_edit="${NOTES_DIR}/${note}" if [ ! -f "${note_to_edit}" ]; then @@ -105,7 +111,7 @@ cmd_edit_note() { cmd_cat_note() { note_index="${1}" - note="$(find_note_name_by_index "${note_index}")" + note="$(show_notes_with_indexes | find_note_name_by_index "${note_index}")" note_to_cat="${NOTES_DIR}/${note}" if [ ! -f "${note_to_cat}" ]; then