X-Git-Url: https://git.sev.monster/~sev/dotfiles.git/blobdiff_plain/f8a63688540cf844bec7dc7b2c9246b64f43350a..c0a11c3801a55ed89dc607c58decccfa143d080b:/bin/mpc-notify diff --git a/bin/mpc-notify b/bin/mpc-notify index 370b6fe..ceecca4 100755 --- a/bin/mpc-notify +++ b/bin/mpc-notify @@ -1,6 +1,47 @@ #!/bin/sh -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": }' 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": }' 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"