]> git.sev.monster Git - dotfiles.git/blob - bin/mpc-notify
Merge branch 'master' of home:git/dotfiles
[dotfiles.git] / bin / mpc-notify
1 #!/bin/sh
2 #TODO: help
3 mpc=mpc
4 dest=org.freedesktop.Notifications
5 opath=/org/freedesktop/Notifications
6 meth=$dest.Notify
7 idfile=~/tmp/mpc-notify.id
8
9 notify() {
10         replaces_id=0
11         if [ -e $idfile ]; then
12                 replaces_id=`cat $idfile`
13         fi
14         echo $(expr "$(gdbus call --session \
15         --dest $dest --object-path $opath --method $meth \
16         mpc $replaces_id audio-volume-high "${1:-$out1}" "${2:-$out2}" '[]' \
17         '{"urgency": <byte 0>}' 3000)" : '(uint32 \([0-9]*\),)') > $idfile
18 }
19
20 getoutput() {
21         #TODO test if not playing for some commands
22         #if mpc -f '' status | awk 'NR==2' | grep -v '^\[playing\]'; then
23         case "$1" in
24                 current)
25                         out1=`$mpc -f %artist% current`
26                         out2="`$mpc -f %title% current`\n`mpc -f %album% current`";;
27                 status) out1=`$mpc current`
28                         out2=`$mpc -f '%album% (%date%)' status`;;
29                 *)       return 1;;
30         esac
31         if [ -z "$out1$out2" ]; then
32                 out1='Stopped'
33         fi
34 }
35
36 cmd=${1:-current}
37 case "$cmd" in
38         -d|--daemon|idle|idleloop)
39                 cmd=${2:-current}
40                 $mpc idleloop player | while read -r x; do
41                         getoutput $cmd
42                         notify "$out1" "$out2"
43                 done
44                 return;;
45         *)      getoutput $cmd || return 1;;
46 esac
47 notify "$out1" "$out2"
This page took 0.043609 seconds and 4 git commands to generate.