Reload disks after invalid choices

This commit is contained in:
Manuel Thalmann 2024-09-22 20:07:19 +02:00
parent bdb16a3e9f
commit 2dd1b1326b

View file

@ -1,5 +1,7 @@
#!/bin/env fish #!/bin/env fish
function chooseDisk -a outFile message function chooseDisk -a outFile message
while true
set -l disks set -l disks
lsblk -do NAME,SIZE,TYPE | while read disk lsblk -do NAME,SIZE,TYPE | while read disk
@ -14,7 +16,6 @@ function chooseDisk -a outFile message
set -l padding (math (string length "$diskCount") + 1) set -l padding (math (string length "$diskCount") + 1)
if [ "$diskCount" -gt 0 ] if [ "$diskCount" -gt 0 ]
while true
echo "$message" echo "$message"
set -l prefix set -l prefix
@ -31,17 +32,19 @@ function chooseDisk -a outFile message
read -lP "Your choice: " choice read -lP "Your choice: " choice
or exit 1 or exit 1
if math "0+$choice" &> /dev/null
if [ "$choice" -ge 1 ] && [ "$choice" -le "$diskCount" ] if [ "$choice" -ge 1 ] && [ "$choice" -le "$diskCount" ]
set -l disk (string split -n " " "$disks[$(math "$choice" + 1)]") set -l disk (string split -n " " "$disks[$(math "$choice" + 1)]")
echo "/dev/$disk[1]" > $outFile echo "/dev/$disk[1]" > $outFile
return return
else end
end
echo "The specified choice \"$choice\" is invalid!" echo "The specified choice \"$choice\" is invalid!"
end
end
else else
echo "No valid disk found!" >&2 echo "No valid disk found!" >&2
end end
end
return 1 return 1
end end