Reload disks after invalid choices
This commit is contained in:
parent
bdb16a3e9f
commit
2dd1b1326b
|
@ -1,20 +1,21 @@
|
|||
#!/bin/env fish
|
||||
function chooseDisk -a outFile message
|
||||
set -l disks
|
||||
|
||||
lsblk -do NAME,SIZE,TYPE | while read disk
|
||||
set -l diskInfo (string split -n " " $disk)
|
||||
while true
|
||||
set -l disks
|
||||
|
||||
if contains "$diskInfo[3]" "TYPE" "disk"
|
||||
set -a disks "$diskInfo"
|
||||
lsblk -do NAME,SIZE,TYPE | while read disk
|
||||
set -l diskInfo (string split -n " " $disk)
|
||||
|
||||
if contains "$diskInfo[3]" "TYPE" "disk"
|
||||
set -a disks "$diskInfo"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
set -l diskCount (count $disks)
|
||||
set -l padding (math (string length "$diskCount") + 1)
|
||||
set -l diskCount (count $disks)
|
||||
set -l padding (math (string length "$diskCount") + 1)
|
||||
|
||||
if [ "$diskCount" -gt 0 ]
|
||||
while true
|
||||
if [ "$diskCount" -gt 0 ]
|
||||
echo "$message"
|
||||
set -l prefix
|
||||
|
||||
|
@ -31,16 +32,18 @@ function chooseDisk -a outFile message
|
|||
read -lP "Your choice: " choice
|
||||
or exit 1
|
||||
|
||||
if [ "$choice" -ge 1 ] && [ "$choice" -le "$diskCount" ]
|
||||
set -l disk (string split -n " " "$disks[$(math "$choice" + 1)]")
|
||||
echo "/dev/$disk[1]" > $outFile
|
||||
return
|
||||
else
|
||||
echo "The specified choice \"$choice\" is invalid!"
|
||||
if math "0+$choice" &> /dev/null
|
||||
if [ "$choice" -ge 1 ] && [ "$choice" -le "$diskCount" ]
|
||||
set -l disk (string split -n " " "$disks[$(math "$choice" + 1)]")
|
||||
echo "/dev/$disk[1]" > $outFile
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
echo "The specified choice \"$choice\" is invalid!"
|
||||
else
|
||||
echo "No valid disk found!" >&2
|
||||
end
|
||||
else
|
||||
echo "No valid disk found!" >&2
|
||||
end
|
||||
|
||||
return 1
|
||||
|
|
Loading…
Reference in a new issue