diff options
| author | Alec Goncharow <alec@goncharow.dev> | 2023-10-27 17:48:41 -0400 |
|---|---|---|
| committer | Alec Goncharow <alec@goncharow.dev> | 2023-10-27 17:48:41 -0400 |
| commit | 253cfd4e49d48ae00f88458034404d3e827563cc (patch) | |
| tree | 5d3eec5e006ef8dbb2c4d563c7a482d9e4508c4b /script_template.sh | |
| parent | 3c56c6c937452002647a5d7b3039c7887b9716b5 (diff) | |
sync
Diffstat (limited to 'script_template.sh')
| -rwxr-xr-x | script_template.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/script_template.sh b/script_template.sh new file mode 100755 index 0000000..854ddfa --- /dev/null +++ b/script_template.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail +if [[ "${TRACE-0}" == "1" ]]; then + set -o xtrace +fi + +prompt_confirm() { + while true; do + read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY + case $REPLY in + [yY]) echo ; return 0 ;; + [nN]) echo ; return 1 ;; + *) printf " \033[31m %s \n\033[0m" "invalid input" + esac + done +} + + +help() { + echo 'Usage: ./script.sh arg-one arg-two + +This is an awesome bash script to make your life better. + +' + exit +} + +if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then + help +fi + +cd "$(dirname "$0")" + +main() { + prompt_confirm "print help?" || exit 0 + help +} + +main "$@" |
