Skip to content

Commit f9c6ef4

Browse files
committed
Merge branch 'notify-module' of https://github.com/micampe/dotzsh into develop
2 parents 6c722fe + 012e49f commit f9c6ef4

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

helper.zsh

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ function format-elapsed {
4545
elif [[ $mins > 0 ]]; then
4646
elapsed+="$mins mins and $secs secs"
4747
elif [[ $secs > 0 ]]; then
48-
elapsed+="$secs.$hsecs secs"
48+
if [[ $hsecs > 0 ]]; then
49+
elapsed+="$secs.$hsecs secs"
50+
else
51+
elapsed+="$secs secs"
52+
fi
4953
elif [[ $msecs > 0 ]]; then
5054
elapsed+="$msecs ms"
5155
else

modules/notify/init.zsh

+25-16
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,58 @@ if [[ ! -z $SSH_CONNECTION ]]; then
1717
return 1
1818
fi
1919

20-
if (( $+commands[growlnotify] )); then
21-
notify_exec="growlnotify"
20+
if (( $+commands[terminal-notifier] )); then
21+
dotzsh_notify_exec="terminal-notifier"
2222
elif [[ -d /Applications/terminal-notifier.app ]]; then
23-
notify_exec="/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier"
23+
dotzsh_notify_exec="/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier"
24+
elif (( $+commands[growlnotify] )); then
25+
dotzsh_notify_exec="growlnotify"
2426
else
2527
return 1
2628
fi
2729

30+
function dotzsh-notify {
31+
if (( $+commands[growlnotify] )); then
32+
${dotzsh_notify_exec} -n "dotzsh-notify" -m ${1} ${2}
33+
elif [[ ! "$dotzsh_notify_exec" == "" ]]; then
34+
${dotzsh_notify_exec} -group "dotzsh-notify" -message ${1} -title ${2} > /dev/null
35+
else
36+
echo "Install growlnotify or terminal-notifier to use the dotzsh notify module"
37+
echo "$2: $1"
38+
fi
39+
}
40+
2841
zstyle -a ':dotzsh:module:notify' elapsed '_elapsed'
2942
if (( $#_elapsed > 0 )); then
3043
notify_max="$_elapsed[@]"
3144
fi
3245

3346
notify_preexec() {
3447
notify_cmd=$1
35-
notify_time=`date +%s%N`
48+
notify_time=`date +%s`
3649
}
3750

3851
notify_precmd() {
3952
exitstatus=$?
40-
stop=$(date +'%s%N')
53+
stop=$(date +'%s')
4154
start=${notify_time:-$stop}
4255
let elapsed=$stop-$start
43-
let elapsedsecs=$(($elapsed / 1000000000 % 1000000000))
4456

4557
max=${notify_max:-30}
4658
alias_notify_cmd=`alias $notify_cmd | awk -F"'" '{print $2}'|awk '{print $1}'`
4759
if [[ "$alias_notify_cmd" == "" ]]; then
4860
alias_notify_cmd=`echo $notify_cmd | awk '{print $1}'`
4961
fi
50-
if [[ ! "$alias_notify_cmd" == (vi|vim|top|ssh|cmatrix|telnet|tmux|mux|workon|) ]]; then
51-
if [[ $elapsedsecs -gt $max ]]; then
62+
if [[ ! "$alias_notify_cmd" == (vi|vim|top|ssh|cmatrix|telnet|tmux|mux|man|workon) ]]; then
63+
if [[ $elapsed -gt $max ]]; then
64+
let elapsed_ns=$(($elapsed * 1000000000))
5265
if [[ $exitstatus == 0 ]]; then
53-
message="Completed after $(format-elapsed $elapsed)"
66+
message="Completed after $(format-elapsed $elapsed_ns)"
5467
else
55-
message="Failed with status $exitstatus after $(format-elapsed $elapsed)"
56-
fi
57-
if [[ -d /Applications/terminal-notifier.app/ ]]; then
58-
${notify_exec} -group dotzshnotify -message ${message} -title ${notify_cmd:-Some command} > /dev/null
59-
else
60-
${notify_exec} -n "dotzshnotify" -m ${message} ${notify_cmd:-Some command}
68+
message="Failed with status $exitstatus after $(format-elapsed $elapsed_ns)"
6169
fi
70+
71+
dotzsh-notify ${message} ${alias_notify_cmd:-Some command}
6272
fi
6373
fi
6474
notify_cmd=
@@ -67,4 +77,3 @@ notify_precmd() {
6777

6878
add-zsh-hook preexec notify_preexec
6979
add-zsh-hook precmd notify_precmd
70-

0 commit comments

Comments
 (0)