@@ -17,48 +17,58 @@ if [[ ! -z $SSH_CONNECTION ]]; then
17
17
return 1
18
18
fi
19
19
20
- if (( $+ commands[growlnotify ] )) ; then
21
- notify_exec= " growlnotify "
20
+ if (( $+ commands[terminal - notifier ] )) ; then
21
+ dotzsh_notify_exec= " terminal-notifier "
22
22
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"
24
26
else
25
27
return 1
26
28
fi
27
29
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
+
28
41
zstyle -a ' :dotzsh:module:notify' elapsed ' _elapsed'
29
42
if (( $# _elapsed > 0 )) ; then
30
43
notify_max=" $_elapsed [@]"
31
44
fi
32
45
33
46
notify_preexec () {
34
47
notify_cmd=$1
35
- notify_time=` date +%s%N `
48
+ notify_time=` date +%s`
36
49
}
37
50
38
51
notify_precmd () {
39
52
exitstatus=$?
40
- stop=$( date +' %s%N ' )
53
+ stop=$( date +' %s' )
41
54
start=${notify_time:- $stop }
42
55
let elapsed=$stop -$start
43
- let elapsedsecs=$(( $elapsed / 1000000000 % 1000000000 ))
44
56
45
57
max=${notify_max:- 30}
46
58
alias_notify_cmd=` alias $notify_cmd | awk -F" '" ' {print $2}' | awk ' {print $1}' `
47
59
if [[ " $alias_notify_cmd " == " " ]]; then
48
60
alias_notify_cmd=` echo $notify_cmd | awk ' {print $1}' `
49
61
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 ))
52
65
if [[ $exitstatus == 0 ]]; then
53
- message=" Completed after $( format-elapsed $elapsed ) "
66
+ message=" Completed after $( format-elapsed $elapsed_ns ) "
54
67
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 ) "
61
69
fi
70
+
71
+ dotzsh-notify ${message} ${alias_notify_cmd:- Some command}
62
72
fi
63
73
fi
64
74
notify_cmd=
@@ -67,4 +77,3 @@ notify_precmd() {
67
77
68
78
add-zsh-hook preexec notify_preexec
69
79
add-zsh-hook precmd notify_precmd
70
-
0 commit comments