Skip to content

Instantly share code, notes, and snippets.

@wojteklu
Last active July 7, 2024 14:20

Revisions

  1. wojteklu revised this gist Oct 2, 2016. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions terminal_notification.md
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,8 @@ function notifyme {
    osascript -e 'on run argv
    tell application "System Events"
    set frontApp to name of first application process whose frontmost is true
    if frontApp is not "Terminal" then
    set notifTitle to item 1 of argv
    if notifTitle starts with "open" is false
    set notifBody to "succeded"
    set errorCode to item 2 of argv
  2. wojteklu revised this gist Oct 2, 2016. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions terminal_notification.md
    Original file line number Diff line number Diff line change
    @@ -7,14 +7,18 @@ function notifyme {
    osascript -e 'on run argv
    tell application "System Events"
    set frontApp to name of first application process whose frontmost is true
    if frontApp is not "Terminal" 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
    if notifTitle starts with "open" is false
    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
    display notification notifBody with title notifTitle
    end if
    end tell
    end run' $CMD $LAST_EXIT_CODE
  3. wojteklu created this gist Jul 6, 2016.
    24 changes: 24 additions & 0 deletions terminal_notification.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    Add the following to your `~/.zshrc`:

    ```bash
    function notifyme {
    LAST_EXIT_CODE=$?
    CMD=$(fc -ln -1)
    osascript -e 'on run argv
    tell application "System Events"
    set frontApp to name of first application process whose frontmost is true
    if frontApp is not "Terminal" 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' $CMD $LAST_EXIT_CODE
    }

    export PS1='$(notifyme)'$PS1
    ```