Last active
October 15, 2021 20:46
-
-
Save elliot-u410/ec65d22b4524a86e2373ecfaa1bcb512 to your computer and use it in GitHub Desktop.
alertcmd.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -uo pipefail | |
: "${ALERT_CMD_THRESHOLD_SECONDS:=5}" | |
: "${ALERT_CMD_SUCCESS_SOUND:=glass}" | |
: "${ALERT_CMD_FAIL_SOUND:=sosumi}" | |
if ! which terminal-notifier > /dev/null; then | |
>&2 echo "Install terminal-notifier!" | |
exit 1 | |
fi | |
start=$(date +%s) | |
"$@" | |
exitcode="$?" | |
end=$(date +%s) | |
runtime=$((end-start)) | |
if (( runtime > ALERT_CMD_THRESHOLD_SECONDS )); then | |
success="failed" | |
sound="$ALERT_CMD_FAIL_SOUND" | |
if [ "$exitcode" = "0" ]; then | |
success="succeeded" | |
sound="$ALERT_CMD_SUCCESS_SOUND" | |
fi | |
terminal-notifier -title "Command $success in ${runtime}s" -message "$*" -sound "$sound" | |
fi | |
exit "$exitcode" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment