dmenu-mpd (1432B)
1 #!/bin/sh 2 # Needs preselect patch for dmenu to preselect item. 3 pgrep -x mpd || mpd 4 export CURRENT_PLAYER="mpd" 5 6 next_song="$(mpc queued)" 7 prev_song="$(($(mpc | awk '/#/{sub(/\/.*/, "", $2);sub(/#/, "", $2);print $2}')-1))" 8 prev_song="$(mpc playlist | sed -n ${prev_song}p)" 9 curr_song="$(mpc --format '[%title%|%file%]' current)" 10 n=0 11 12 [ ! "$next_song" ] || btn_next="ﭠ Next Song (\"$next_song\")" 13 [ ! "$prev_song" ] || btn_prev="ﭢ Prev Song (\"$prev_song\")" 14 [ ! "$curr_song" ] || btn_play=" Play (\"$curr_song\")" \ 15 && btn_pause=" Pause (\"$curr_song\")" && mpc status | grep -q 'playing' \ 16 && btn_curr="$btn_pause" || btn_curr="$btn_play" 17 ([ "$btn_curr" ] || [ "$btn_next" ] || [ "$btn_prev" ]) && \ 18 seperator="-----------------------------------------------------------------------------------" 19 20 [ ! "$btn_next" ] || n="$((n+1))" 21 [ ! "$btn_prev" ] || n="$((n+1))" 22 [ ! "$btn_curr" ] || n="$((n+1))" 23 [ ! "$seperator" ] || n="$((n+1))" 24 25 menu="$btn_prev 26 $btn_curr 27 $btn_next 28 $seperator 29 $(mpc listall | sort)" 30 menu="$(printf "%s" "${menu}" | sed '/^\s*$/d')" 31 32 choice="$(printf "%s" "${menu}" | dmenu -i -n "$n" -l 20)" 33 34 if [ "$choice" ]; then 35 case "$choice" in 36 "$btn_play"|"$btn_pause") mpc -q toggle ;; 37 "$btn_next") mpc -q next ;; 38 "$btn_prev") mpc -q prev ;; 39 *) mpc add "$choice" && mpc play $(mpc playlist | wc -l);; 40 esac 41 fi