From e24566b9186d578d42749c499dd624ae1052235d Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 23 Apr 2023 09:12:01 -0300 Subject: bin/boop: Add "-x"option to notify only when COMMAND fails --- bin/boop | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/boop b/bin/boop index 546c95c..c9e6ff7 100755 --- a/bin/boop +++ b/bin/boop @@ -16,6 +16,7 @@ help() { -m MESSAGE text message of the desktop notification (default: COMMAND) -n don't play any sound + -x only notify when COMMAND fails -h, --help show this message COMMAND the commands to be executed @@ -51,7 +52,8 @@ for flag in "$@"; do done SOUND=-s -while getopts 'm:nh' flag; do +SILENT=false +while getopts 'm:nxh' flag; do case "$flag" in m) MESSAGE="$OPTARG" @@ -59,6 +61,9 @@ while getopts 'm:nh' flag; do n) SOUND= ;; + x) + SILENT=true + ;; h) usage help @@ -73,6 +78,8 @@ done shift $((OPTIND - 1)) +CMD="$*" + set +e "$@" STATUS=$? @@ -84,7 +91,8 @@ else N=1 fi -CMD="$*" -msg -"$N" -b $SOUND -D "${MESSAGE:-$CMD}" +if [ "$N" = 1 ] || [ "$SILENT" = false ]; then + msg -"$N" -b $SOUND -D "${MESSAGE:-$CMD}" +fi exit "$STATUS" -- cgit v1.2.3