From 3417d513260c8900eca7e90202f3f6434af9d693 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Sat, 22 Dec 2018 23:09:22 +0200 Subject: [PATCH] return with numkey --- shell/select-option.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shell/select-option.sh b/shell/select-option.sh index 0cd524b..3f97ec8 100755 --- a/shell/select-option.sh +++ b/shell/select-option.sh @@ -34,7 +34,9 @@ function select_option { get_cursor_row() { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; } key_input() { read -s -n1 key1 2>/dev/null >&2 read -s -n2 -t 0.1 key2 2>/dev/null >&2 - + if [[ "$key1" =~ ^[0-9]+$ ]]; then + echo $key1; return; + fi if [[ $key1$key2 = $ESC[A ]]; then echo up; return; fi if [[ $key1$key2 = $ESC[B ]]; then echo down; return; fi if [[ $key1 = $'\e' ]]; then echo esc; return; fi @@ -78,20 +80,21 @@ function select_option { done # user key control - case `key_input` in + local user_input=`key_input` + case "$user_input" in enter) break;; esc) reset_display; exit 1;; up) ((selected--)); if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi;; down) ((selected++)); if [ $selected -ge $# ]; then selected=0; fi;; + [0-9]) selected=$(( $user_input - 1 )); break;; esac done # cursor position back to normal cursor_to $lastrow - printf "\n" - cursor_blink_on + reset_display if [[ -n "$SELECT_TOFILE" ]]; then local idx=0 for opt; do