Skip to content

Instantly share code, notes, and snippets.

@marcransome
Last active June 17, 2022 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcransome/8ceb28a21fecc958521a042a3b81d028 to your computer and use it in GitHub Desktop.
Save marcransome/8ceb28a21fecc958521a042a3b81d028 to your computer and use it in GitHub Desktop.
sure.fish
$the_cow = <<EOC;
|
v
__
/ \
| |
@ @
|| ||
|| ||
\___/
EOC
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