mirror of
https://github.com/prurigro/vnotes.git
synced 2024-11-22 09:14:10 -05:00
Declare variables more appropriately
This commit is contained in:
parent
940cb59e00
commit
29b50cc2b9
1 changed files with 9 additions and 13 deletions
22
vnotes
22
vnotes
|
@ -17,13 +17,13 @@ VNOTES_FOLDER=${VNOTES_FOLDER:="$HOME/Notes"}
|
||||||
VNOTES_EXTENSION=${NOTES_SUFFIX:='md'}
|
VNOTES_EXTENSION=${NOTES_SUFFIX:='md'}
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
deps=('dd' 'getkeycodes' 'od' 'stty' 'tput')
|
declare -a deps=('dd' 'getkeycodes' 'od' 'stty' 'tput')
|
||||||
|
|
||||||
|
# Declare global variables
|
||||||
declare -a documents=()
|
declare -a documents=()
|
||||||
declare one_display=''
|
declare -i max_docwidth=0 upto=0
|
||||||
declare upto=''
|
one_display=''
|
||||||
declare tty_state=''
|
tty_state=''
|
||||||
declare max_docwidth=0
|
|
||||||
|
|
||||||
# Colour Scheme
|
# Colour Scheme
|
||||||
[[ -t 1 ]] && {
|
[[ -t 1 ]] && {
|
||||||
|
@ -100,7 +100,7 @@ function prompt {
|
||||||
|
|
||||||
# Calculates a number to the power of another
|
# Calculates a number to the power of another
|
||||||
function power {
|
function power {
|
||||||
local number="$1" power="$2" total=1
|
local -i number="$1" power="$2" total=1
|
||||||
|
|
||||||
for (( x=0; x<"$power"; x++ )); do
|
for (( x=0; x<"$power"; x++ )); do
|
||||||
total=$(( total * number ))
|
total=$(( total * number ))
|
||||||
|
@ -128,7 +128,8 @@ function search_notes {
|
||||||
local key="$1"
|
local key="$1"
|
||||||
|
|
||||||
# Declare local variables we'll be using
|
# Declare local variables we'll be using
|
||||||
local screen_width maxcolumns digits digits_power cnt count_display value keypress
|
local -i screen_width=0 maxcolumns=0 digits=1 digits_power cnt=1
|
||||||
|
local 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
|
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
|
||||||
|
@ -185,9 +186,7 @@ function search_notes {
|
||||||
# Display the multiple matching documents (or the full list if no term was passed)
|
# Display the multiple matching documents (or the full list if no term was passed)
|
||||||
screen_width=$(tput cols)
|
screen_width=$(tput cols)
|
||||||
|
|
||||||
if [[ -n "$screen_width" ]]; then
|
if (( screen_width > 0 )); then
|
||||||
maxcolumns=0
|
|
||||||
|
|
||||||
while (( 1 )); do
|
while (( 1 )); do
|
||||||
(( ((max_docwidth + 8) * maxcolumns) > screen_width )) && {
|
(( ((max_docwidth + 8) * maxcolumns) > screen_width )) && {
|
||||||
(( maxcolumns-- ))
|
(( maxcolumns-- ))
|
||||||
|
@ -204,8 +203,6 @@ function search_notes {
|
||||||
upto=${#documents[@]}
|
upto=${#documents[@]}
|
||||||
|
|
||||||
# Calculate the number of digits in $upto
|
# Calculate the number of digits in $upto
|
||||||
digits=1
|
|
||||||
|
|
||||||
while (( 1 )); do
|
while (( 1 )); do
|
||||||
digits_power=$(power 10 $digits)
|
digits_power=$(power 10 $digits)
|
||||||
(( (upto / digits_power) < 1 )) && break
|
(( (upto / digits_power) < 1 )) && break
|
||||||
|
@ -214,7 +211,6 @@ function search_notes {
|
||||||
|
|
||||||
# Draw the list
|
# Draw the list
|
||||||
printf '\n'
|
printf '\n'
|
||||||
cnt=1
|
|
||||||
|
|
||||||
for (( x=0; x<${#documents[*]}; x++ )); do
|
for (( x=0; x<${#documents[*]}; x++ )); do
|
||||||
count_display=$(printf "%${digits}s" "$(( x + 1 ))")
|
count_display=$(printf "%${digits}s" "$(( x + 1 ))")
|
||||||
|
|
Loading…
Reference in a new issue