-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifyosd.zsh
59 lines (54 loc) · 1.78 KB
/
notifyosd.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# https://github.com/ihashacks/notifyosd.zsh/blob/master/notifyosd.zsh
# commands to ignore
cmdignore=(htop tmux top vim)
# set gt 0 to enable GNU units for time results
gnuunits=0
# end and compare timer, notify-send if needed
function notifyosd-precmd() {
retval=$?
if [[ ${cmdignore[(r)$cmd_basename]} == $cmd_basename ]]; then
return
else
if [ ! -z "$cmd" ]; then
cmd_end=`date +%s`
((cmd_secs=$cmd_end - $cmd_start))
fi
if [ $retval -gt 0 ]; then
cmdstat="with warning"
sndstat="/usr/share/sounds/gnome/default/alerts/sonar.ogg"
urgency="critical"
else
cmdstat="successfully"
sndstat="/usr/share/sounds/gnome/default/alerts/glass.ogg"
urgency="normal"
fi
if [ ! -z "$cmd" -a $cmd_secs -gt 10 ]; then
if [ $gnuunits -gt 0 ]; then
cmd_time=$(units "$cmd_secs seconds" "centuries;years;months;weeks;days;hours;minutes;seconds" | \
sed -e 's/\ +/\,/g' -e s'/\t//')
else
cmd_time="$cmd_secs seconds"
fi
if [ ! -z $SSH_TTY ] ; then
notify-send -i utilities-terminal \
-u $urgency "$cmd_basename on `hostname` completed $cmdstat" "\"$cmd\" took $cmd_time"; \
play -q $sndstat
else
notify-send -i utilities-terminal \
-u $urgency "$cmd_basename completed $cmdstat" "\"$cmd\" took $cmd_time"; \
play -q $sndstat
fi
fi
unset cmd
fi
}
# make sure this plays nicely with any existing precmd
precmd_functions+=( notifyosd-precmd )
# get command name and start the timer
function notifyosd-preexec() {
cmd=$1
cmd_basename=${${cmd:s/sudo //}[(ws: :)1]}
cmd_start=`date +%s`
}
# make sure this plays nicely with any existing preexec
preexec_functions+=( notifyosd-preexec )