-replaces_id=0
-mpc idleloop player | while read -r x; do
- #notify-send -u low -t 3000 -a mpc "`mpc current`"
- replaces_id=$(expr "$(gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.Notify mpc $replaces_id 'audio-volume-high' "`mpc current`" '' '[]' '{"urgency": <byte 0>}' 3000)" : '(uint32 \([0-9]*\),)')
-done
+#TODO: help
+mpc=mpc
+dest=org.freedesktop.Notifications
+opath=/org/freedesktop/Notifications
+meth=$dest.Notify
+idfile=~/tmp/mpc-notify.id
+
+notify() {
+ replaces_id=0
+ if [ -e $idfile ]; then
+ replaces_id=`cat $idfile`
+ fi
+ echo $(expr "$(gdbus call --session \
+ --dest $dest --object-path $opath --method $meth \
+ mpc $replaces_id audio-volume-high "${1:-$out1}" "${2:-$out2}" '[]' \
+ '{"urgency": <byte 0>}' 3000)" : '(uint32 \([0-9]*\),)') > $idfile
+}
+
+getoutput() {
+ #TODO test if not playing for some commands
+ #if mpc -f '' status | awk 'NR==2' | grep -v '^\[playing\]'; then
+ case "$1" in
+ current)
+ out1=`$mpc -f %artist% current`
+ out2="`$mpc -f %title% current`\n`mpc -f %album% current`";;
+ status) out1=`$mpc current`
+ out2=`$mpc -f '%album% (%date%)' status`;;
+ *) return 1;;
+ esac
+ if [ -z "$out1$out2" ]; then
+ out1='Stopped'
+ fi
+}
+
+cmd=${1:-current}
+case "$cmd" in
+ -d|--daemon|idle|idleloop)
+ cmd=${2:-current}
+ $mpc idleloop player | while read -r x; do
+ getoutput $cmd
+ notify "$out1" "$out2"
+ done
+ return;;
+ *) getoutput $cmd || return 1;;
+esac
+notify "$out1" "$out2"