-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify-send
executable file
·137 lines (121 loc) · 2.95 KB
/
notify-send
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/zsh
maxthres=5
thres=$maxthres
duration=5
xnotify(){
heading="${(Q)1}"
shift
rest="$@"
rest=${(Q)rest}
text=$(echo "^fg(green)$heading[1,15]: ^fg(grey85)$rest" | perl -pe 'if (!eof()) { s/\n/ | /g }' | tr -dc '[:print:]' )
echo "$text" | dzen2 -p $duration -xs 2 -y -1 &!
}
cnotify(){
tmux display-message '$@'
#muxSend a "echo $@ | head -1 | tr '\n' ' | ' | tr -dc '[:print:]' "
}
type=xnotify
export DISPLAY=":0"
pidof X &>/dev/null || type=cnotify
NFILE="/dev/shm/.notify-counter"
if [[ $1 == "-f" ]];then
shift
duration=2
$type "$@"
exit
fi
if [[ ! -f $NFILE ]];then
temp=$(date +%s)
echo "$temp|shot|$maxthres" >| $NFILE
echo " " >> $NFILE
njiffy=$temp
mode=shot
time=$temp
difference=100
else
t=$(< $NFILE)
temp=$t[(f)1]
p_subject=$t[(f)2]
njiffy=$temp[(ws:|:)1]
mode=$temp[(ws:|:)2]
thres=$temp[(ws:|:)3]
time=$(date +%s)
difference=$(( $time - $njiffy ))
fi
if [[ $mode == temper || ($difference -lt 2 && $1 == $p_subject ) ]];then
if [[ $thres == 0 ]];then
if [[ ! $mode == "temper" ]];then
notify-send -f "Warning" "Too many notifications - check:/tmp/notifications"
mode="temper"
fi
echo "$time|$mode|$maxthres" >| $NFILE
echo "$1" >> $NFILE
echo "$(date -R): $@" >>| /tmp/notifications
exit
else
thres=$(( (thres-1)%$maxthres ))
fi
elif [[ $difference -lt 10 ]];then
mode="batch"
thres=10
duration=2
else
mode="shot"
duration=7
thres=10
fi
echo "$time|$mode|$thres" >| $NFILE
echo "$1" >> $NFILE
#set +x
prgm=$0
if [[ -n $1 ]];then
param="${(qq)1}"
shift
mlog="${(qq)@}"
if [[ ! -t 0 ]];then
while read LINE
do
mlog="$mlog ${(qq)LINE}"
done
fi
else
if [[ -t 0 ]];then
notify-send "Warning" "Wrong input"
exit
fi
param="Subject"
tempReply=""
while read LINE
do
tempReply="$tempReply ${(qq)LINE}"
done
echo -e "STDIN \n$(date '+%F %H:%M') ==> $param: $tempReply\n" >>| ~/.notify-history
$type "$param" "$tempReply"
exit
fi
if [[ $prgm == *aria* ]];then
param="aria2c"
fi
if [[ $prgm == *beuter* ]];then
mlog="^i(/home/raghavendra/.notify-icons/beuter.xpm)$param $mlog"
param="beuter"
fi
echo -e "\n$(date '+%F %H:%M') ==> $mlog\n" >> ~/.notify-history
case $param in
*rtorrent*)
$type "Torrent download" "^i(/home/raghavendra/.notify-icons/torrent.xpm)$mlog download complete!"
consume $HOME/.dque
;;
*aria2c*)
message=$(tail -1 ~/.download_history |cut -d ' ' -f 1 | cut -d : -f 2-)
$type "Aria2:" "^i(/home/raghavendra/.notify-icons/download.xpm)${message:t} download complete"
consume $HOME/.dque
;;
*beuter*)
$type "Newsbeuter" "$mlog"
;;
*mail*)
$type "New Mail" "$mlog"
;;
*) $type "$param" "$mlog"
esac