Skip to content

Instantly share code, notes, and snippets.

@StringManolo
Created October 29, 2025 03:57
Show Gist options
  • Select an option

  • Save StringManolo/8d27a298915982143f85408a6a924523 to your computer and use it in GitHub Desktop.

Select an option

Save StringManolo/8d27a298915982143f85408a6a924523 to your computer and use it in GitHub Desktop.
Basic select menu.sh
#!/bin/sh
options="Opción1 Opción2 Opción3 Opción4"
selected=0
len=$(echo $options | wc -w)
draw() {
i=0
clear
for opt in $options; do
if [ $i -eq $selected ]; then
printf "\033[97;44m%s\033[0m\n" "$opt"
else
printf "\033[97m%s\033[0m\n" "$opt"
fi
i=$((i+1))
done
}
readkey() {
stty -echo -icanon min 1 time 0
dd bs=1 count=1 2>/dev/null
stty sane
}
while :; do
draw
key=$(readkey)
if [ "$key" = "$(printf '\n')" ]; then
break
elif [ "$key" = "$(printf '\033')" ]; then
k2=$(readkey)
k3=$(readkey)
case "$k2$k3" in
"[A") [ $selected -gt 0 ] && selected=$((selected-1)) ;;
"[B") [ $selected -lt $((len-1)) ] && selected=$((selected+1)) ;;
esac
fi
done
i=0
for opt in $options; do
[ $i -eq $selected ] && echo "Seleccionaste: $opt"
i=$((i+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment