| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Shows macOS desktop notifications when a command completes. |
| 4 | # Depending on exit status of the command, a different notification message is shown. |
| 5 | # |
| 6 | # Examples: |
| 7 | # misc/nofify make -j 8 >/dev/null |
| 8 | # Make all font styles in all formats without printing detailed messages |
| 9 | # |
| 10 | # misc/notify make Regular |
| 11 | # Make the regular style in all formats |
| 12 | # |
| 13 | |
| 14 | HAS_NOTIFIER=true |
| 15 | if ! (which terminal-notifier >/dev/null); then |
| 16 | HAS_NOTIFIER=false |
| 17 | echo "$0: terminal-notifier not found in PATH (will not notify)" >&2 |
| 18 | echo "$0: You can install through: brew install terminal-notifier" |
| 19 | fi |
| 20 | |
| 21 | CMDS="$@" |
| 22 | "$@" |
| 23 | STATUS=$? |
| 24 | |
| 25 | if $HAS_NOTIFIER; then |
| 26 | if [[ $STATUS -eq 0 ]]; then |
| 27 | terminal-notifier \ |
| 28 | -title "$1 ✅" \ |
| 29 | -message "$CMDS" \ |
| 30 | -activate com.apple.Terminal \ |
| 31 | -timeout 8 >/dev/null & |
| 32 | else |
| 33 | terminal-notifier \ |
| 34 | -title "$1 failed ❌" \ |
| 35 | -message "$CMDS => $STATUS" \ |
| 36 | -activate com.apple.Terminal \ |
| 37 | -timeout 20 >/dev/null & |
| 38 | fi |
| 39 | fi |
| 40 | |
| 41 | exit $STATUS |