Skip to content

Instantly share code, notes, and snippets.

@Techcable
Last active August 18, 2023 21:49
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 Techcable/20e39efc9fe9b460b9ccb2671bba46df to your computer and use it in GitHub Desktop.
Save Techcable/20e39efc9fe9b460b9ccb2671bba46df to your computer and use it in GitHub Desktop.
#!/bin/sh
confirm() {
local prompt="$1";
local default;
case "$2" in
true | True | yes)
default="True";
;;
false | False | no)
default="False";
;;
*)
echo "Internal error: Invalid default \`$2\`" >&2;
exit 1;
;;
esac
python3 -c "import sys, rich.prompt; exit(not rich.prompt.Confirm.ask(sys.argv[1], default=$default))" "$prompt";
return $?;
}
if confirm "Foo?" "yes"; then
echo "Returned true";
else
echo "Returned false";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment