feat: Make the first item the default selection in select menus when no input is provided.
This commit is contained in:
parent
ca54f17189
commit
7e5e40c447
1 changed files with 8 additions and 2 deletions
10
z.sh
10
z.sh
|
|
@ -15,8 +15,11 @@ if [ ${#disks[@]} -eq 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PS3="Select a disk to choose partitions from: "
|
PS3="Select a disk to choose partitions from (default 1): "
|
||||||
select disk_info in "${disks[@]}"; do
|
select disk_info in "${disks[@]}"; do
|
||||||
|
if [[ -z "$REPLY" ]]; then
|
||||||
|
disk_info="${disks[0]}"
|
||||||
|
fi
|
||||||
if [[ -n "$disk_info" ]]; then
|
if [[ -n "$disk_info" ]]; then
|
||||||
selected_disk=$(echo "$disk_info" | awk '{print $1}')
|
selected_disk=$(echo "$disk_info" | awk '{print $1}')
|
||||||
break
|
break
|
||||||
|
|
@ -44,9 +47,12 @@ get_partition() {
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "$prompt"
|
echo "$prompt"
|
||||||
PS3="$ps3_val"
|
PS3="$ps3_val (default 1): "
|
||||||
local selection
|
local selection
|
||||||
select selection in "${parts[@]}"; do
|
select selection in "${parts[@]}"; do
|
||||||
|
if [[ -z "$REPLY" ]]; then
|
||||||
|
selection="${parts[0]}"
|
||||||
|
fi
|
||||||
if [[ -n "$selection" ]]; then
|
if [[ -n "$selection" ]]; then
|
||||||
eval "$var_name=$(echo "$selection" | cut -d' ' -f1)"
|
eval "$var_name=$(echo "$selection" | cut -d' ' -f1)"
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue