diff options
author | EuAndreh <eu@euandre.org> | 2022-11-17 17:58:41 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-11-17 17:58:41 -0300 |
commit | 62ca1a97e0848ef5f9043da69c6af8a9b0bb9808 (patch) | |
tree | 9fa23a49cf205c7162a3604418775cbc798ee3c7 /bin/prompt | |
parent | Initial empty commit (diff) | |
parent | opt/bin-dirs/clisp: Include custom build of CLISP (diff) | |
download | dotfiles-62ca1a97e0848ef5f9043da69c6af8a9b0bb9808.tar.gz dotfiles-62ca1a97e0848ef5f9043da69c6af8a9b0bb9808.tar.xz |
Merge remote-tracking branch 'tilde/main'
Diffstat (limited to 'bin/prompt')
-rwxr-xr-x | bin/prompt | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/bin/prompt b/bin/prompt new file mode 100755 index 0000000..247c81a --- /dev/null +++ b/bin/prompt @@ -0,0 +1,76 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + prompt STRING|- + prompt -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + STRING the text to be displayed in the prompt + + + Display a prompt and return a value corresponding to the + response. + + + Examples: + + Conditionally run download command + + if prompt 'Download files?'; then + run_download; + fi + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +STRING="${1:-}" +eval "$(assert-arg "$STRING" 'STRING')" + +printf '%s' "$STRING" +printf ' [Y/n]: ' +read -r yesno +if [ "$yesno" != 'n' ] && [ "$yesno" != 'N' ]; then + exit 0 +else + exit 1 +fi |