From 940cb59e00ff40132384f85e09150505a25dfbd1 Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Wed, 23 Aug 2023 23:52:15 -0400 Subject: [PATCH] Declare variables used locally in functions as local (and don't worry about unsetting them) --- vnotes | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/vnotes b/vnotes index e902620..c8cbb09 100755 --- a/vnotes +++ b/vnotes @@ -42,7 +42,8 @@ declare max_docwidth=0 # Display help text function help { - script_name="${0//*\/}" + local script_name="${0//*\/}" + printf '\n%s\n\n' "${c_m}vnotes${c_w} - manage your notes$c_c" printf '%s\n' "${c_b}USAGE$c_c" printf ' %-43s%s\n' "${c_d}[${c_y}PATTERN$c_d]$c_c" ' — opens single match or lists multiple' @@ -55,8 +56,7 @@ function help { # Create a note function create_note { if [[ -n "$1" ]]; then - note="$VNOTES_FOLDER/${1}.$VNOTES_EXTENSION" - "$EDITOR" "$note" + "$EDITOR" "$VNOTES_FOLDER/${1}.$VNOTES_EXTENSION" else printf '%s %s\n' "${c_r}ERROR:$c_c" "${c_w}The name of the note to ${c_y}create$c_w was not provided$c_c" >&2 exit 1 @@ -65,6 +65,8 @@ function create_note { # Delete a note function delete_note { + local note + if [[ -n "$1" ]]; then note="$VNOTES_FOLDER/${1}.$VNOTES_EXTENSION" @@ -122,10 +124,15 @@ function open_note { # Search for notes and open the closest match, or list out options if more than one exists function search_notes { - # Take the first input as the key - key="$1" + # Declare the search term as "key" + local key="$1" + + # Declare local variables we'll be using + local screen_width maxcolumns digits digits_power cnt count_display value keypress # Declare variables with the keycodes for "Q", "q", return/enter and 0-9 + local alpha_Q alpha_q key_cr key_0 key_1 key_2 key_3 key_4 key_5 key_6 key_7 key_8 key_9 + alpha_Q=$(getkeycode "$(printf '%s' 'Q' | od -t o1)") alpha_q=$(getkeycode "$(printf '%s' 'q' | od -t o1)") key_cr=$(getkeycode "$(printf '\n' | od -t o1)") @@ -205,8 +212,6 @@ function search_notes { (( digits++ )) done - unset digits_power - # Draw the list printf '\n' cnt=1 @@ -227,7 +232,6 @@ function search_notes { fi done - unset cnt printf '\n' # Initialize the interactive entry line