summaryrefslogtreecommitdiffstats
path: root/notify-send
blob: a8d507a7e969da615ecc4cd4da23b69b5d2eea7b (plain)
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
#!/bin/zsh
pidof X &>/dev/null || exit 0
source ~/config/profile
duration=${DURATION:-5}
sdate=${SDATE:-1}
maximum=3
displacement=16
y=1
export DISPLAY=":0"
type=xnotify
pidof X &>/dev/null || type=cnotify
prgm=$0
[[ $sdate == 1 ]] && date=$(date -R)

xnotify(){
    heading="${(Q)1}"
    shift
    rest="[email protected]"
    rest=${(Q)rest}
    DZENARG="$DZENARG -p $duration"
    text=$(echo "^fg(green)$heading[1,15]: ^fg(grey85)$rest" | perl -pe 'if (!eof()) { s/\n/ | /g }' | tr -dc '[:print:]' )
    if [[ $sdate == 1 ]];then 
        echo "^fg(white)At $date:          $text" | dzen2 $DZENARG -y $y &!
    else
        echo "$text" | dzen2 $DZENARG -y $y &!
    fi
}

xnotify_exp(){
    heading="${(Q)1}"
    shift
    rest="[email protected]"
    lines=5
    DZENARG="$DZENARG -l $lines -p $duration"
    (print "$heading"; print -l ${(f)rest}) | dzen2 ${(Q)DZENARG}  &!
}

cnotify(){
   if pidof tmux;then
       tmux display-message '[email protected]'
    else
        echo "[email protected]" | write raghavendra /dev/tty1
    fi
}

num=$(pgrep dzen2 | wc -l)
num=$(( $num % (maximum+1) ))
if [[ $num > $maximum ]];then
    sleep $(( duration*num ))
else
    y=$(( y + num*displacement ))
    sleep $num
fi

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