====== Job Notification ====== **execute your custom commands when your program exceed $_spantime minutes** *used the preexec and precmd of Zshall **Please note it is not useful when suspend job control used, I hope some day zshall will** **have some build-in for this utilities.** **Useful in situations you have to wait for long builds, tests, regressions and you forget to append a mail command** **?? Is there is some machinism to know some program is interactive program like emacs, vi so we can bar them, like recognizing that they all may be using ncurse, or canonical/non-canonical/raw I/O usage. so we can employee `exec > `tty` > ~/outputlog ' so for long running we could be able to notify and as well as save the flying output in some logfile if some user forget to redirect it.** _spantime=15 # 15 mins, if don't want to pollute env, put its value directly. preexec () { pgmname1=$1 pgmname2=$2 pgmname3=$3 starttime=`date +%s`; } precmd () { if (( $#starttime )) ; then span=$( expr `date +%s` - $starttime ) if (( $span > ${_spantime:-15} * 60 )) ; then your-choice-command mail $LOGNAME@sasken.com -s "$span : $pgmname1, exit code $?" <<<"Hi $LOGNAME command have taken more time $span seconds. $pgmname1 exit code $? $pgmname2 $pgmname3 bye" fi unset span fi unset pgmname1 pgmname2 pgmname3 starttime } ====== Set mailpath ====== **set mailpath directly from mailboxes in ~/.muttrc** mailpath=( ${(f)"$(sed -n \ 's@^[[:space:]]\+mailboxes[[:space:]]\+\(.*\)[[:space:]]*$@\1?new mail in ^[[5;36m${_:t}^[[0;39m, try ^[[0;32mmutt -f ${_//$HOME/~}^[[0;39m@p' \ ~/.mutt/muttrc | sed s@\^\~@$HOME@)"} ) or with autoload -U colors && colors mailpath=( ${(f)"$(sed -n \ 's@^[[:space:]]\+mailboxes[[:space:]]\+\(.*\)[[:space:]]*$@\1?new mail in ${fg_no_bold[cyan]}${_:t}${reset_color}, try ${fg_no_bold[green]}mutt -f ${_//$HOME/\~}${reset_color}@p' \ ~/.mutt/muttrc | sed s@\^\~@$HOME@)"} )