-
Notifications
You must be signed in to change notification settings - Fork 13
/
notifyre.sh
executable file
·81 lines (67 loc) · 1.68 KB
/
notifyre.sh
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# maintained at
# https://github.com/kaustubhhiware/NotiFyre
#
# Author: Kaustubh Hiware (hiwarekaustubh@googlemail.com)
#
SOUND=1
SOUND_MIN=10
ALERT=/usr/share/sounds/ubuntu/notifications/Slick.ogg
MIN_INTERVAL=4
notifyre() {
start=$(date +%s)
commandx=$@
"$@"
notif_timer
}
alias nf='notifyre'
# plain printer,
notif_timer() {
# check for new terminal condition, start is unitialised ? set it to current time
if [ -z $start ]; then
start=$(date +%s)
fi
i="$IFS";IFS='/'
set -f
p=($PWD)
set +f
IFS="$i"
end=$(date +%s)
elapsed=$((end - start))
if [[ "$RETVAL" -ne 0 ]]; then
command_status="\u274c"
else
command_status="\u2705"
fi
if [ "$(uname -s)" = "Darwin" ]; then
if [ "$elapsed" -gt "$MIN_INTERVAL" ]; then
# Use terminal-notifier for Mac OS
terminal-notifier -title "NotiFyre $(echo $command_status)" \
-subtitle "Command : $commandx" \
-message "Completed in $elapsed seconds" \
-timeout 5 \
-closeLabel "Gotcha!"
fi
else
if [ "$elapsed" -gt "$MIN_INTERVAL" ]; then
# Use notify-send for others
notify-send "NotiFyre $(echo -e $command_status)" \
"Terminal in ${p[-2]}/${p[-1]}\nCompleted $commandx in $elapsed seconds" \
-i utilities-terminal \
-t 5000
fi
if [ "$SOUND" -eq 1 ] && [ "$elapsed" -gt "$SOUND_MIN" ]; then
paplay $ALERT &> /dev/null || echo -en "\a";
fi
fi
}
# needs .bash-preexec.sh
# if you wish not to get notified for all processes, comment the line
# source ~/.bash-preexec.sh # as close to the end as possible in ~/.bashrc
preexec() {
commandx="$1"
start=$(date +%s)
}
precmd() {
notif_timer
}