PortValhalla/lib/modules/partition/confirm.fish

31 lines
633 B
Fish
Raw Permalink Normal View History

2024-09-22 16:51:10 +00:00
#!/bin/env fish
function confirm -a message default
set -l options (echo "[y/n]" | string replace "$default" (string upper "$default"))
2024-09-22 16:51:10 +00:00
while true
read -l value -P "$message $options "
or exit 1
2024-10-06 19:25:34 +00:00
2024-09-22 16:51:10 +00:00
set value (string lower "$value")
if [ -z "$value" ]
set value $default
end
2024-10-06 19:25:34 +00:00
if contains "$value" 0 false n no
2024-09-22 16:51:10 +00:00
false
return
end
2024-10-06 19:25:34 +00:00
if contains "$value" 1 true y yes
2024-09-22 16:51:10 +00:00
true
return
end
echo "The specified value `$value` is invalid!"
echo "Please try again"
end
end
confirm $argv