2

Use Case
I am trying to send growl notices after a long terminal action has occurred. I'd like to be lazy and automatically be able to pass to growl the command that just occurred.

So I'd like to be able to run
npm install; growl

and have the growl function command pass through 'npm install' so I can get notified that that was the command that just finished.

I have the following in my .zshrc file:

p () { echo $1 }

I'm trying to echo the first half of this command:

ls; p

I really want the p function to output ls so I can send a notification about what was just executed.

My use case is that I'm trying to growlnotify myself when a command has finished by tacking ; p or && p at the end of it.

For the life of me I can't figure this out.

Jamis Charles
  • 5,827
  • 8
  • 32
  • 42

2 Answers2

3

You would need to write the function like this:

p () {
    $@ # execute cmd line
    growl "$@" # send notification
}

Then call it like this:

p ls -al 
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • This is great! Working well. This outputs `ls`. Any way I can output the params as well? `ls -al`. Including multiple params? – Jamis Charles Aug 30 '14 at 09:42
  • For me it works with `ls -al`. (I'm just using `echo` for testing, never heard about `growl` before.) – hek2mgl Aug 30 '14 at 09:43
  • Echo was working, but growl wasn't. This did it for me: `output="$@"` `growl $output`. Thank you. Perfect now. – Jamis Charles Aug 30 '14 at 09:52
  • Unfortunately can't test, I've read it is OSX specific. However, nice to hear it is working :) – hek2mgl Aug 30 '14 at 09:55
  • 1
    One more tiny thing, not a huge deal. This won't allow for aliases. So if my alias is `gs` I can't run `p gs`. This may be something I can live with if it's not doable, as I can simply have the alias include the `p` command – Jamis Charles Aug 30 '14 at 09:58
0
p () {
    $@;
    msg=$@

    # If using Maverick you can spawn a notification like this: 
    # http://apple.stackexchange.com/a/115373
    cmd="display notification \"${msg}\" with title \"Command Finished\""
    osascript -e "$cmd"
}
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123