diff options
-rwxr-xr-x | bin/boop | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/bin/boop b/bin/boop new file mode 100755 index 0000000..2b45422 --- /dev/null +++ b/bin/boop @@ -0,0 +1,74 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + boop -- COMMAND... + boop -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + COMMAND the commands to be executed + + + Examples: + + Play the positive sound: + + $ boop echo 123 + + Fail with the underlying 127 return code: + + $ boop ech 123 + 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)) + + +set +e +"$@" +STATUS=$? +set -e + +if [ "$STATUS" = 0 ]; then + play "$XDG_DATA_HOME"/msg/good.ogg 2>/dev/null +else + play "$XDG_DATA_HOME"/msg/bad.ogg 2>/dev/null +fi + +exit "$STATUS" |