2024-09-22 16:24:07 +00:00
|
|
|
#!/bin/env fish
|
2024-09-30 12:36:20 +00:00
|
|
|
function chooseDisk -a outFile message selectScript
|
|
|
|
if [ -z "$selectScript" ]
|
|
|
|
set selectScript "$(status dirname)/select.fish"
|
|
|
|
end
|
|
|
|
|
|
|
|
source "$selectScript"
|
2024-09-22 16:24:07 +00:00
|
|
|
|
2024-09-22 18:07:19 +00:00
|
|
|
while true
|
2024-09-30 12:36:20 +00:00
|
|
|
set -l header
|
2024-09-22 18:07:19 +00:00
|
|
|
set -l disks
|
2024-09-22 16:24:07 +00:00
|
|
|
|
2024-09-30 12:36:20 +00:00
|
|
|
lsblk -do NAME,SIZE,TYPE | begin
|
|
|
|
read header
|
2024-09-22 18:07:19 +00:00
|
|
|
|
2024-09-30 12:36:20 +00:00
|
|
|
cat | while read disk
|
|
|
|
set -l diskInfo (string split -n " " $disk)
|
2024-09-22 16:24:07 +00:00
|
|
|
|
2024-09-30 12:36:20 +00:00
|
|
|
if contains "$diskInfo[3]" "disk"
|
|
|
|
set -a disks "$disk"
|
2024-09-22 18:07:19 +00:00
|
|
|
end
|
2024-09-22 16:24:07 +00:00
|
|
|
end
|
2024-09-30 12:36:20 +00:00
|
|
|
end
|
2024-09-22 18:07:19 +00:00
|
|
|
|
2024-09-30 12:36:20 +00:00
|
|
|
select "$header" "$outFile" "$message" "No valid disk found!" "$(string collect $disks)" "false"
|
|
|
|
and begin
|
|
|
|
set -l disk (string split -n " " (cat "$outFile"))
|
|
|
|
echo "/dev/$disk[1]" > $outFile
|
|
|
|
return
|
2024-09-22 16:24:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
chooseDisk $argv
|