Skip to content

Instantly share code, notes, and snippets.

@jazlopez
Last active February 26, 2023 08:51
Show Gist options
  • Save jazlopez/d6ef3966a6b7bd8cdc258cbed596f842 to your computer and use it in GitHub Desktop.
Save jazlopez/d6ef3966a6b7bd8cdc258cbed596f842 to your computer and use it in GitHub Desktop.
menu arrow down up selection bash
awsprofiles(){
grep -Eo "\[.*\]" $HOME/.aws/credentials | sed 's/[][]//g' | nl
}
prompt_goto(){
local mopts=$1
tput cup $mopts 1
echo "Go to: "
tput cup $mopts 8
}
clear
max=$(($(cat <(awsprofiles) | wc -l)-1))
mopts=$((max+4))
# echo $max
awsprofiles
c=1
tput cup 0 1
while true # Forever = until ctrl+c
do
# r: backslash is not for escape
# s: silent
# "n x": read x chars before returning
read -rsn 1
case $REPLY in
g|G)
prompt_goto $mopts
read
if [[ $REPLY -gt $max ]]; then
c=$((max))
else
c=$((REPLY-1))
fi;
tput cup $c 1
;;
q|Q)
break;;
A)
if [[ $c -gt 1 ]]; then
c=$((c-1))
tput cuu 1
else
c=$max
tput cup $max 1
fi
;;
B)
if [[ $c -eq $max ]]; then
c=1
tput cup 0 1
else
c=$((c+1))
tput cud1
fi
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment