add preselection

This commit is contained in:
2023-08-17 09:11:45 +03:00
parent 13a18b779c
commit cb425c5bd1

View File

@@ -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; }