try [ for test

master
amelia 1 year ago
parent 50da0973fb
commit 79c6b1beaa

@ -57,7 +57,7 @@ deleteFirst() {
shift shift
MENUSTACK="" MENUSTACK=""
for menu in $@; do for menu in $@; do
if [[ "$MENUSTACK" = "" ]]; then if [ "$MENUSTACK" = "" ]; then
MENUSTACK="$menu" MENUSTACK="$menu"
else else
MENUSTACK="$MENUSTACK|$menu" MENUSTACK="$MENUSTACK|$menu"
@ -73,28 +73,28 @@ clrline() {
relamove() { relamove() {
# relamove 1 -2 = move right 1 and down 2 # relamove 1 -2 = move right 1 and down 2
if [[ "$2" -gt 0 ]]; then if [ "$2" -gt 0 ]; then
printf "\033["$2"A" printf "\033["$2"A"
elif [[ "$2" -lt 0 ]]; then elif [ "$2" -lt 0 ]; then
invert=$(echo $2 | cut -d'-' -f 2) invert=$(echo $2 | cut -d'-' -f 2)
printf "\033["$invert"B" printf "\033["$invert"B"
fi fi
if [[ "$1" -gt 0 ]]; then if [ "$1" -gt 0 ]; then
printf "\033["$1"C" printf "\033["$1"C"
elif [[ "$1" -lt 0 ]]; then elif [ "$1" -lt 0 ]; then
invert=$(echo $1 | cut -d'-' -f 2) invert=$(echo $1 | cut -d'-' -f 2)
printf "\033["$invert"D" printf "\033["$invert"D"
fi fi
} }
menumove() { menumove() {
if [[ "$1" -lt 0 && $(($MENUPOS - $1)) -lt $MENUSIZE ]]; then if [ "$1" -lt 0 && $(($MENUPOS - $1)) -lt $MENUSIZE ]; then
printf " " printf " "
relamove -1 $1 relamove -1 $1
printf "*" printf "*"
relamove -1 0 relamove -1 0
MENUPOS=$(($MENUPOS - $1)) MENUPOS=$(($MENUPOS - $1))
elif [[ "$1" -gt 0 && $(($MENUPOS - $1)) -ge 0 ]]; then elif [ "$1" -gt 0 && $(($MENUPOS - $1)) -ge 0 ]; then
printf " " printf " "
relamove -1 $1 relamove -1 $1
printf "*" printf "*"
@ -132,14 +132,14 @@ split_ls2() {
drawmenu() { drawmenu() {
# initialize menu only. too expensize to do each time # initialize menu only. too expensize to do each time
IFS="|" IFS="|"
if [[ "$1" = "Back" && "$(length $MENUSTACK)" -gt 1 ]]; then if [ "$1" = "Back" && "$(length $MENUSTACK)" -gt 1 ]; then
deleteFirst $MENUSTACK deleteFirst $MENUSTACK
elif [[ $(getNth 0 "$MENUSTACK") != "$1" && "$1" != "Back" && "$MODE" = "" ]]; then elif [ $(getNth 0 "$MENUSTACK") != "$1" && "$1" != "Back" && "$MODE" = "" ]; then
addFirst $1 addFirst $1
logprint "Adding $1" logprint "Adding $1"
logprint "State: $MENUSTACK" logprint "State: $MENUSTACK"
fi fi
if [[ "$MODE" != "" ]]; then if [ "$MODE" != "" ]; then
CURRENTMENU="$1" # when not using the stack, pull directly from the arg list CURRENTMENU="$1" # when not using the stack, pull directly from the arg list
else else
CURRENTMENU="$(getNth 0 $MENUSTACK)" CURRENTMENU="$(getNth 0 $MENUSTACK)"
@ -162,7 +162,7 @@ drawmenu() {
done done
logprint "Old size: $OLDMENUSIZE, New size $MENUSIZE" logprint "Old size: $OLDMENUSIZE, New size $MENUSIZE"
IFS=$oldifs IFS=$oldifs
if [[ "$OLDMENUSIZE" -gt "$MENUSIZE" ]]; then if [ "$OLDMENUSIZE" -gt "$MENUSIZE" ]; then
for line in $(seq $(($OLDMENUSIZE - $MENUSIZE))); do for line in $(seq $(($OLDMENUSIZE - $MENUSIZE))); do
relamove 0 -1 relamove 0 -1
clrline clrline
@ -180,12 +180,12 @@ selected() {
IFS="/" IFS="/"
temp_pos_count=0 temp_pos_count=0
for line in $CURRENTMENU; do for line in $CURRENTMENU; do
if [[ "$temp_pos_count" = "$MENUPOS" ]]; then if [ "$temp_pos_count" = "$MENUPOS" ]; then
IFS=$oldifs IFS=$oldifs
logprint "Got: $(eval echo \"\$$line\")" logprint "Got: $(eval echo \"\$$line\")"
if [[ "$MODE" != "" ]]; then if [ "$MODE" != "" ]; then
$MODE "$line" $MODE "$line"
elif [[ "$(eval echo \"\$$line\")" = "" ]]; then elif [ "$(eval echo \"\$$line\")" = "" ]; then
clear clear
"$line" # execute function "$line" # execute function
sleep 0.5 sleep 0.5
@ -214,7 +214,7 @@ else
fi fi
# check for root util # check for root util
if [[ "$USER" = "root" ]]; then if [ "$USER" = "root" ]; then
rootcmd="" rootcmd=""
elif which sudo; then elif which sudo; then
rootcmd="sudo" rootcmd="sudo"
@ -237,7 +237,7 @@ while read -rsn1 ui; do
# Flush read. We account for sequences for Fx keys as # Flush read. We account for sequences for Fx keys as
# well. 6 should suffice far more then enough. # well. 6 should suffice far more then enough.
read -rsn1 -t 0.01 tmp read -rsn1 -t 0.01 tmp
if [[ "$tmp" == "[" ]]; then if [ "$tmp" == "[" ]; then
read -rsn1 -t 0.01 tmp read -rsn1 -t 0.01 tmp
case "$tmp" in case "$tmp" in
"A") menumove 1;; # up "A") menumove 1;; # up

Loading…
Cancel
Save