Last active
January 17, 2019 19:37
-
-
Save dfed/a8882b849905a377742624b43026f086 to your computer and use it in GitHub Desktop.
Post macOS notification when your terminal command is done
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
brew install terminal-notifier | |
function notify { | |
local title="Succeeded" | |
# Capture the parameter list for later display. | |
local message=$@ | |
if [ $# -ne 0 ]; then | |
# Execute the parameters. | |
eval $@ | |
else | |
# Get the last line of history. | |
message="$(history 1 | awk '{$1="";$2="";print}')" | |
fi | |
# Get the exit status of the last-run command. | |
local retVal=$? | |
if [ $retVal -ne 0 ]; then | |
title="Failed" | |
fi | |
# Notify the user that the command is done. | |
terminal-notifier -title "$title" -message "$message" -sound "default" -ignoreDnD | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment