Fix selected-row when clear options hidden

main
Elnu 3 years ago
parent 5a6fde43da
commit af0e116895

@ -11,6 +11,7 @@ CLEAR=" Clear all"
clear="${CLEAR}${NL}" clear="${CLEAR}${NL}"
CLEAR_COMPLETED=" Clear completed" CLEAR_COMPLETED=" Clear completed"
clear_completed="${CLEAR_COMPLETED}${NL}" clear_completed="${CLEAR_COMPLETED}${NL}"
selected_row=2
# Read checlist file # Read checlist file
touch $FILE touch $FILE
@ -24,7 +25,7 @@ list=${list//"$EMPTY_RAW"/"$EMPTY"} # empty checkboxes
list=${list//"$FILLED_RAW"/"$FILLED"} # filled checkboxes list=${list//"$FILLED_RAW"/"$FILLED"} # filled checkboxes
# Don't show clear all option if task list is empty # Don't show clear all option if task list is empty
[[ -z $list ]] && clear="" [[ -z $list ]] && { clear=""; selected_row=$(($selected_row - 1)); }
# Don't show clear completed option if there are no completed tasks # Don't show clear completed option if there are no completed tasks
count=${#list_raw_array[*]} count=${#list_raw_array[*]}
@ -38,7 +39,7 @@ while [ $i -lt $count ]; do
fi fi
i=$(($i + 1)) i=$(($i + 1))
done done
[[ $completed_tasks = "n" ]] && clear_completed="" [[ $completed_tasks = "n" ]] && { clear_completed=""; selected_row=$(($selected_row - 1)); }
# Check for rofi/dmenu # Check for rofi/dmenu
exe_exists() { exe_exists() {
@ -56,7 +57,7 @@ fi
case $menu in case $menu in
rofi) rofi)
exe_exists rofi || { echo "rofi isn't installed"; exit 1; } exe_exists rofi || { echo "rofi isn't installed"; exit 1; }
command="rofi -dmenu"; options="-selected-row 2" ;; command="rofi -dmenu"; options="-selected-row $selected_row" ;;
dmenu) dmenu)
exe_exists dmenu || { echo "dmenu isn't installed"; exit 1; } exe_exists dmenu || { echo "dmenu isn't installed"; exit 1; }
command=dmenu; options="-l 10" ;; command=dmenu; options="-l 10" ;;