Last active
August 18, 2023 21:49
-
-
Save Techcable/20e39efc9fe9b460b9ccb2671bba46df to your computer and use it in GitHub Desktop.
Shell confirmation via Python rich - https://rich.readthedocs.io/en/latest/reference/prompt.html#rich.prompt.Confirm
This file contains hidden or 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
#!/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