PortValhalla/lib/modules/partition/choose-disk.fish

35 lines
843 B
Fish
Raw Normal View History

#!/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 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-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-30 12:36:20 +00:00
if contains "$diskInfo[3]" "disk"
set -a disks "$disk"
2024-09-22 18:07:19 +00:00
end
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
end
end
end
chooseDisk $argv