aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-06-15 18:15:36 -0300
committerEuAndreh <eu@euandre.org>2022-06-15 18:15:36 -0300
commit8c7d3c182872b6bcd03b45f0f1e25a83aae9de92 (patch)
tree3d306fe64eb8fc0a9ca613f8c46e02acb07bed2f
parentmv share/msg: medium -> good, low -> bad (diff)
downloaddotfiles-8c7d3c182872b6bcd03b45f0f1e25a83aae9de92.tar.gz
dotfiles-8c7d3c182872b6bcd03b45f0f1e25a83aae9de92.tar.xz
bin/boop: Add working version
-rwxr-xr-xbin/boop74
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"