From cb425c5bd1e34c4285c9dd774251ebae30ca75d1 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Thu, 17 Aug 2023 09:11:45 +0300 Subject: [PATCH] add preselection --- shell/select-option.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shell/select-option.sh b/shell/select-option.sh index 9a0b5ad..64d1266 100755 --- a/shell/select-option.sh +++ b/shell/select-option.sh @@ -11,6 +11,7 @@ function select_option { local shortcuts=() local idx=0 local clean_opt + local selected=$SELECT_SELECT for opt; do multiselected+=(0) if [[ "$opt" =~ ^\[.\] ]]; then # choice starts with [x] @@ -102,13 +103,10 @@ function select_option { local lborderchars="|:'" local rborderchars="|:." - - # ensure cursor and input echoing back on upon a ctrl+c during read -s trap "cursor_blink_on; stty echo; printf '\n'; exit 1" 2 cursor_blink_off - local selected=0 local bottomlength=$(( 10 + $max_opt )) local multiselect_pos=6 if [[ $SELECT_NUMBERS -eq 1 ]]; then @@ -219,6 +217,7 @@ _help() { --center Center box on screen --middle Clear screen and position in the middle --timeout # Set timeout in seconds + --select # Go to a row when starting. 0 = first item -o File Save the choice(s) in a file. -_ Print spaces instead of underscores, workaround for shell arguments containing spaces. @@ -280,6 +279,7 @@ SELECT_MIDDLE=0 SELECT_TOFILE="" SELECT_TITLE="" SELECT_TIMEOUT="" +SELECT_SELECT=0 for (( i=1; i<=$#; i++ )); do value=${!i} j=$(( i + 1 )) @@ -290,6 +290,7 @@ for (( i=1; i<=$#; i++ )); do [[ "$value" = "--middle" ]] && { SELECT_MIDDLE=1; continue; } [[ "$value" = "--title" ]] && { SELECT_TITLE="${!j}"; ((i++)); continue; } [[ "$value" = "--timeout" ]] && { SELECT_TIMEOUT="-t ${!j}"; ((i++)); continue; } + [[ "$value" = "--select" ]] && { SELECT_SELECT="${!j}"; ((i++)); continue; } [[ "${value}" = "-"* ]] && { [[ "$value" =~ -.*h ]] && { _help; } [[ "$value" =~ -.*m ]] && { SELECT_MULTI=1; }