Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Would like an alias to read the part of the current command line that precedes the alias



On Oct 10, 2011, at 10:05 PM, Bart Schaefer wrote:

> However, I suspect most zsh users would do this with a precmd function,
> and never type out the "; alert" at all.  For example:

Here's my attempt to build a version for Mac.

I'm having two problems:

First, and I think this is general, it triggers again off of a blank command line (i.e. pressing return a second time) after the specified time has elapsed. This is the second growlnotify call below.

Second, and this is probably due to my setup, I can't get the failure detection working. The third growlnotify call below should have a -a argument of "Problem Reporter".

Any idea what I'm doing wrong?

pro% echo $ZSH_VERSION 
4.3.9
pro% setopt
extendedglob
interactive
login
monitor
shinstdin
zle
pro% typeset -f preexec precmd
preexec () {
	SECONDS=0 
}
precmd () {
	(( SECONDS > 1 )) && growlnotify -p "Very Low" -a "${${?/0/Terminal}//<->*/Problem Reporter}" -m $history[$[HISTCMD-1]]
}
pro% cat succeed 
#!/bin/zsh
sleep 2
pro% cat fail 
#!/bin/zsh
sleep 2
exit 1
pro% set -x
+precmd:1> ((  SECONDS > 1  ))
pro% ./succeed 
+preexec:1> SECONDS=0 
+-zsh:7> ./succeed
+precmd:1> ((  SECONDS > 1  ))
+precmd:3> growlnotify -p 'Very Low' -a Terminal -m ./succeed
pro% 
+precmd:1> ((  SECONDS > 1  ))
+precmd:3> growlnotify -p 'Very Low' -a Terminal -m ./succeed
pro% ./fail 
+preexec:1> SECONDS=0 
+-zsh:9> ./fail
+precmd:1> ((  SECONDS > 1  ))
+precmd:3> growlnotify -p 'Very Low' -a Terminal -m ./fail
pro% 
-- 
Aaron Davies
aaron.davies@xxxxxxxxx


Messages sorted by: Reverse Date, Date, Thread, Author