http://frantic.im/notify-on-completion
create script:
#!/usr/bin/env osascript
on run argv
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
if frontApp is not "iTerm2" then
set notifTitle to item 1 of argv
set notifBody to "succeded"
set errorCode to item 2 of argv
if errorCode is not "0"
set notifBody to "failed with error code " & errorCode
end if
display notification notifBody with title notifTitle
end if
end tell
end run
Then in my .zshrc:
function f_notifyme {
LAST_EXIT_CODE=$?
CMD=$(fc -ln -1)
# No point in waiting for the command to complete
notifyme "$CMD" "$LAST_EXIT_CODE" &
}
export PS1='$(f_notifyme)'$PS1