add preselection
This commit is contained in:
@@ -11,6 +11,7 @@ function select_option {
|
|||||||
local shortcuts=()
|
local shortcuts=()
|
||||||
local idx=0
|
local idx=0
|
||||||
local clean_opt
|
local clean_opt
|
||||||
|
local selected=$SELECT_SELECT
|
||||||
for opt; do
|
for opt; do
|
||||||
multiselected+=(0)
|
multiselected+=(0)
|
||||||
if [[ "$opt" =~ ^\[.\] ]]; then # choice starts with [x]
|
if [[ "$opt" =~ ^\[.\] ]]; then # choice starts with [x]
|
||||||
@@ -102,13 +103,10 @@ function select_option {
|
|||||||
local lborderchars="|:'"
|
local lborderchars="|:'"
|
||||||
local rborderchars="|:."
|
local rborderchars="|:."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ensure cursor and input echoing back on upon a ctrl+c during read -s
|
# 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
|
trap "cursor_blink_on; stty echo; printf '\n'; exit 1" 2
|
||||||
cursor_blink_off
|
cursor_blink_off
|
||||||
|
|
||||||
local selected=0
|
|
||||||
local bottomlength=$(( 10 + $max_opt ))
|
local bottomlength=$(( 10 + $max_opt ))
|
||||||
local multiselect_pos=6
|
local multiselect_pos=6
|
||||||
if [[ $SELECT_NUMBERS -eq 1 ]]; then
|
if [[ $SELECT_NUMBERS -eq 1 ]]; then
|
||||||
@@ -219,6 +217,7 @@ _help() {
|
|||||||
--center Center box on screen
|
--center Center box on screen
|
||||||
--middle Clear screen and position in the middle
|
--middle Clear screen and position in the middle
|
||||||
--timeout # Set timeout in seconds
|
--timeout # Set timeout in seconds
|
||||||
|
--select # Go to a row when starting. 0 = first item
|
||||||
-o File Save the choice(s) in a file.
|
-o File Save the choice(s) in a file.
|
||||||
-_ Print spaces instead of underscores, workaround for
|
-_ Print spaces instead of underscores, workaround for
|
||||||
shell arguments containing spaces.
|
shell arguments containing spaces.
|
||||||
@@ -280,6 +279,7 @@ SELECT_MIDDLE=0
|
|||||||
SELECT_TOFILE=""
|
SELECT_TOFILE=""
|
||||||
SELECT_TITLE=""
|
SELECT_TITLE=""
|
||||||
SELECT_TIMEOUT=""
|
SELECT_TIMEOUT=""
|
||||||
|
SELECT_SELECT=0
|
||||||
for (( i=1; i<=$#; i++ )); do
|
for (( i=1; i<=$#; i++ )); do
|
||||||
value=${!i}
|
value=${!i}
|
||||||
j=$(( i + 1 ))
|
j=$(( i + 1 ))
|
||||||
@@ -290,6 +290,7 @@ for (( i=1; i<=$#; i++ )); do
|
|||||||
[[ "$value" = "--middle" ]] && { SELECT_MIDDLE=1; continue; }
|
[[ "$value" = "--middle" ]] && { SELECT_MIDDLE=1; continue; }
|
||||||
[[ "$value" = "--title" ]] && { SELECT_TITLE="${!j}"; ((i++)); continue; }
|
[[ "$value" = "--title" ]] && { SELECT_TITLE="${!j}"; ((i++)); continue; }
|
||||||
[[ "$value" = "--timeout" ]] && { SELECT_TIMEOUT="-t ${!j}"; ((i++)); continue; }
|
[[ "$value" = "--timeout" ]] && { SELECT_TIMEOUT="-t ${!j}"; ((i++)); continue; }
|
||||||
|
[[ "$value" = "--select" ]] && { SELECT_SELECT="${!j}"; ((i++)); continue; }
|
||||||
[[ "${value}" = "-"* ]] && {
|
[[ "${value}" = "-"* ]] && {
|
||||||
[[ "$value" =~ -.*h ]] && { _help; }
|
[[ "$value" =~ -.*h ]] && { _help; }
|
||||||
[[ "$value" =~ -.*m ]] && { SELECT_MULTI=1; }
|
[[ "$value" =~ -.*m ]] && { SELECT_MULTI=1; }
|
||||||
|
|||||||
Reference in New Issue
Block a user