I have no problem creating the menu - that is not what this question is about.
What happens however is I go from having the arrow keys be useful (scroll up and down to get access to previous commands I've run at the command line) to completely useless (^[[A^[[A^[[A^[[B^[[C^[[D^[[C
)
Is there any way to encapsulate that behaviour into a menu?
E.g. can I use the scroll up and down keys to access previous options I've selected. (It's a BIG menu and I have MANY options like dev.client.alpha
or dev.otherclient.beta
etc...)
I supposed I could break each one into separate files and just use the command line diredtly OR I could pass an augment to the menu so as to call: ~/menu dev.clint.alpha
directly from the command line.
Just curious is anyone else has (had) this itch and if anything has ever been done about it?
Menu I'm presently using is done basically as follows:
while :
clear
do
echo "$MENU"
read CHOICE ARG1 ARG2 ARG3 ARG4 overflow
case $CHOICE in
command.a)
# do stuff here
;;
command.b)
# do different stuff here
;;
*) # catch all...
continue
;;
esac
done
clear
答案 0 :(得分:2)
您可以通过在阅读时启用 readline 来执行您想要的操作, 并附加每个选项回复内部历史记录。你甚至可以保存 文件的历史记录,所以当你重新运行脚本时,你就有了旧文件 历史。例如:
HISTFILE=/tmp/myhistory
history -r # read old history
while :
do echo "MENU. a b q"
read -e # sets REPLY, enables readline
history -s "$REPLY" # add to history
history -w # save to file
set -- $REPLY
CHOICE=$1; shift
ARG1=$1 ARG2=$2 ARG3=$3 ARG4=$4; shift 4
overflow="$*"
case $CHOICE in
a) echo do stuff here $ARG1 ;;
b) echo do different stuff here ;;
q) exit ;;
*) echo catch all...
continue ;;
esac
done