Last active
June 17, 2022 16:07
-
-
Save marcransome/8ceb28a21fecc958521a042a3b81d028 to your computer and use it in GitHub Desktop.
sure.fish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$the_cow = <<EOC; | |
| | |
v | |
__ | |
/ \ | |
| | | |
@ @ | |
|| || | |
|| || | |
\___/ | |
EOC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sure -d "Request user confirmation before running command with arguments" | |
argparse --stop-nonopt 'h/help' 'v/verbose' -- $argv | |
if test -n "$_flag_help"; or test (count $argv) -eq 0 | |
echo "usage: sure [-h|--help] cmd [args]" | |
return 0 | |
end | |
cowsay -f clippy -W 30 "You're about to run $argv[1]. Are you sure?" | lolcat | |
echo | |
if test (count $argv) -gt 1; and test -n "$_flag_verbose" | |
echo -n " cmd: " | |
echo $argv[1] | lolcat | |
echo " args: [" | |
for arg in $argv[2..-1] | |
echo " $arg" | lolcat | |
end | |
echo -e " ]\n" | |
end | |
read -l -P "(y/n): " confirm | |
while true | |
switch $confirm | |
case Y y | |
# for context on using string escape to preserve quotes see: https://github.com/fish-shell/fish-shell/issues/3708 | |
eval (string escape -- $argv) | |
break | |
case '' N n | |
return 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment