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-10-06 19:25:34 +00:00
|
|
|
if contains "$diskInfo[3]" disk
|
2024-09-30 12:36:20 +00:00
|
|
|
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-12-07 16:43:53 +00:00
|
|
|
select "$header" "$outFile" "$message" "No valid device found!" "$(string collect $disks)" false
|
2024-09-30 12:36:20 +00:00
|
|
|
and begin
|
|
|
|
set -l disk (string split -n " " (cat "$outFile"))
|
2024-10-06 19:25:34 +00:00
|
|
|
echo "/dev/$disk[1]" >$outFile
|
2024-09-30 12:36:20 +00:00
|
|
|
return
|
2024-09-22 16:24:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
chooseDisk $argv
|