mirror of
https://github.com/prurigro/vnotes.git
synced 2024-11-25 10:31:25 -05:00
Declare variables used locally in functions as local (and don't worry about unsetting them)
This commit is contained in:
parent
0930e740f4
commit
940cb59e00
1 changed files with 12 additions and 8 deletions
20
vnotes
20
vnotes
|
@ -42,7 +42,8 @@ declare max_docwidth=0
|
||||||
|
|
||||||
# Display help text
|
# Display help text
|
||||||
function help {
|
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 '\n%s\n\n' "${c_m}vnotes${c_w} - manage your notes$c_c"
|
||||||
printf '%s\n' "${c_b}USAGE$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'
|
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
|
# Create a note
|
||||||
function create_note {
|
function create_note {
|
||||||
if [[ -n "$1" ]]; then
|
if [[ -n "$1" ]]; then
|
||||||
note="$VNOTES_FOLDER/${1}.$VNOTES_EXTENSION"
|
"$EDITOR" "$VNOTES_FOLDER/${1}.$VNOTES_EXTENSION"
|
||||||
"$EDITOR" "$note"
|
|
||||||
else
|
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
|
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
|
exit 1
|
||||||
|
@ -65,6 +65,8 @@ function create_note {
|
||||||
|
|
||||||
# Delete a note
|
# Delete a note
|
||||||
function delete_note {
|
function delete_note {
|
||||||
|
local note
|
||||||
|
|
||||||
if [[ -n "$1" ]]; then
|
if [[ -n "$1" ]]; then
|
||||||
note="$VNOTES_FOLDER/${1}.$VNOTES_EXTENSION"
|
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
|
# Search for notes and open the closest match, or list out options if more than one exists
|
||||||
function search_notes {
|
function search_notes {
|
||||||
# Take the first input as the key
|
# Declare the search term as "key"
|
||||||
key="$1"
|
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
|
# 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)")
|
||||||
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)")
|
key_cr=$(getkeycode "$(printf '\n' | od -t o1)")
|
||||||
|
@ -205,8 +212,6 @@ function search_notes {
|
||||||
(( digits++ ))
|
(( digits++ ))
|
||||||
done
|
done
|
||||||
|
|
||||||
unset digits_power
|
|
||||||
|
|
||||||
# Draw the list
|
# Draw the list
|
||||||
printf '\n'
|
printf '\n'
|
||||||
cnt=1
|
cnt=1
|
||||||
|
@ -227,7 +232,6 @@ function search_notes {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
unset cnt
|
|
||||||
printf '\n'
|
printf '\n'
|
||||||
|
|
||||||
# Initialize the interactive entry line
|
# Initialize the interactive entry line
|
||||||
|
|
Loading…
Reference in a new issue