zsh-users
 help / color / mirror / code / Atom feed
* command completion notification
@ 2012-08-04  6:08 William G. Scott
  2012-08-04 23:10 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: William G. Scott @ 2012-08-04  6:08 UTC (permalink / raw)
  To: zsh-users

Forgive me, as it has been a few years since my last email…

In OS X, 10.8 (aka Mtn Lion), Apple has introduced a notification system.  Using gem, I installed a command-line utility called terminal-notifier.

I wrote a simple function to test its capabilities:

function tnot { "$@" && terminal-notifier -message "$( echo $@ ) returned $?" -title "Command $HISTCMD Completed" >|/dev/null }

Now if I issue a command like

tnot  sleep 12

It will post a notification on the screen and log the notification to the so-called notification center where all the nagging notices pile up.

This isn't particularly elegant.  I would rather use this as a preexec function, or something similar, so I wouldn't have to explicitly type "tnot".  However, there are only a small subset of commands I would want to bind to a notification.

Is it straightforward to somehow bind this to, say, control-return, or some other modified return key sequence?

Thanks.

Bill Scott




William G. Scott
Professor
Department of Chemistry and Biochemistry
and The Center for the Molecular Biology of RNA
228 Sinsheimer Laboratories
University of California at Santa Cruz
Santa Cruz, California 95064
USA
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: command completion notification
  2012-08-04  6:08 command completion notification William G. Scott
@ 2012-08-04 23:10 ` Bart Schaefer
  2012-08-05  3:43   ` William Scott
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2012-08-04 23:10 UTC (permalink / raw)
  To: zsh-users

On Aug 3, 11:08pm, William G. Scott wrote:
}
} In OS X, 10.8 (aka Mtn Lion), Apple has introduced a notification
} system. Using gem, I installed a command-line utility called
} terminal-notifier.
}
} This isn't particularly elegant. I would rather use this as a preexec
} function, or something similar, so I wouldn't have to explicitly type
} "tnot". However, there are only a small subset of commands I would
} want to bind to a notification.

There was a thread from last October about using growl for this same
sort of thing.  See http://www.zsh.org/mla/users/2011/msg00798.html
and surrounding conversation.

} Is it straightforward to somehow bind this to, say, control-return, or
} some other modified return key sequence?

There are two issues here:

(1) Your terminal emulator (I presume just the MacOS terminal app) must
send a recognizable different character or key sequence when you press
control-return -- I'm not in front of my Mac so can't test that now.

(2) It depends on what you want the binding to do.  For example, to
simply insert "tnot" in front of the current command and then run it:

tnot-widget() { BUFFER="tnot $BUFFER"; zle accept-line }
zle -N tnot-widget

and then bindkey for whatever character is sent by control-return, to
the tnot-widget.

I expect you're going to have more trouble with (1).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: command completion notification
  2012-08-04 23:10 ` Bart Schaefer
@ 2012-08-05  3:43   ` William Scott
  2012-08-05 18:21     ` Bart Schaefer
  2012-09-20  9:04     ` Oliver Kiddle
  0 siblings, 2 replies; 5+ messages in thread
From: William Scott @ 2012-08-05  3:43 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Dear Bart:

Thanks for writing back. and  for your advice.

On Aug 4, 2012, at 4:10 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:

> 
> There was a thread from last October about using growl for this same
> sort of thing.  See http://www.zsh.org/mla/users/2011/msg00798.html
> and surrounding conversation.

The site is down, but I will take a look when I can.  I was in fact using growl, 
but never got beyond this.  I wound up aliasing a few commands to run growl-notify.
I wouldn't mind a general solution, as growl probably isn't going to disappear.
> 
> 
> There are two issues here:
> 
> (1) Your terminal emulator (I presume just the MacOS terminal app) must
> send a recognizable different character or key sequence when you press
> control-return -- I'm not in front of my Mac so can't test that now.
> 
> (2) It depends on what you want the binding to do.  For example, to
> simply insert "tnot" in front of the current command and then run it:
> 
> tnot-widget() { BUFFER="tnot $BUFFER"; zle accept-line }
> zle -N tnot-widget
> 
> and then bindkey for whatever character is sent by control-return, to
> the tnot-widget.
> 
> I expect you're going to have more trouble with (1).

You suspected correctly.  (2) worked like a charm, and am embarrassed since I read that chapter in your book last night.

I'm still trying to figure out how to do (1) in some reasonably elegant manner. I'm using iTerm, since it is a bit more amenable to zsh scripting control than terminal, and it in fact has a built-in growl notification, but it is overkill, so I wind up turning it off.

Maybe I am taking a stupid approach.  What would be ideal is if a user could specify a time in seconds beyond which the notification would be issued.  I am most interested in this for processes that take minutes to hours, rather than a few seconds to run in the foreground, and it would also be nice for background processes as well.

Thanks for setting me on the right track.

-- Bill


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: command completion notification
  2012-08-05  3:43   ` William Scott
@ 2012-08-05 18:21     ` Bart Schaefer
  2012-09-20  9:04     ` Oliver Kiddle
  1 sibling, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2012-08-05 18:21 UTC (permalink / raw)
  To: zsh-users

On Aug 4,  8:43pm, William Scott wrote:
}
} > (2) It depends on what you want the binding to do.  For example, to
} > simply insert "tnot" in front of the current command and then run it:
} > 
} > tnot-widget() { BUFFER="tnot $BUFFER"; zle accept-line }
} > zle -N tnot-widget
} 
} (2) worked like a charm, and am embarrassed since I read that chapter
} in your book last night.

You must mean Peter, Jerry and Oliver's book (credit where due).

} Maybe I am taking a stupid approach. What would be ideal is if a user
} could specify a time in seconds beyond which the notification would be
} issued.

I don't think there's anything particular wrong with the approach.  You
can check the shell variable $SECONDS before and after the command is
run to see how much time has expired and only issue the notice if the
difference is large enough.  The example from last October does this by
saving $SECONDS in preexec and the comparing it in precmd, but it can
also be done entirely inside a wrapper like your tnot function.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: command completion notification
  2012-08-05  3:43   ` William Scott
  2012-08-05 18:21     ` Bart Schaefer
@ 2012-09-20  9:04     ` Oliver Kiddle
  1 sibling, 0 replies; 5+ messages in thread
From: Oliver Kiddle @ 2012-09-20  9:04 UTC (permalink / raw)
  To: zsh-users

> On Aug 4, 2012, at 4:10 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> > There was a thread from last October about using growl for this same
> > sort of thing.  See http://www.zsh.org/mla/users/2011/msg00798.html
> > and surrounding conversation.

I missed this and the October thread so it is perhaps a bit late.

Instead of saving and checking SECONDS, I simply check TTYIDLE from
precmd(). This is more useful because you'll only get an alert for
a terminal that you have left alone as opposed to one where you were
interacting with a console-based program.

Recentish xterm has a feature for setting the window manager urgency
hint and my usual window manager (i3) handles that in a manner that
isn't too irritating. Unfortunately, it is tied in with the bell so I
need to use a visual bell and print a bell character \a: a beep would
be irritating. I'm not familiar with growl but the main advantage of an
xterm feature is that you don't have to worry about the effect of ssh
to remote machines or su to different users. Still, it ends up being
annoying at times.

Oliver


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-09-20  9:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-04  6:08 command completion notification William G. Scott
2012-08-04 23:10 ` Bart Schaefer
2012-08-05  3:43   ` William Scott
2012-08-05 18:21     ` Bart Schaefer
2012-09-20  9:04     ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).