aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2015-05-16 14:14:49 +0200
committerDuncaen <mail@duncano.de>2015-05-16 14:14:49 +0200
commit515b693e6171b456ebc1dc7d1bd469c13c6b386d (patch)
tree59a47d2ac1131574ad87084b4d7369a1744a4e5e
parent9de285f8d88bf92037845396fe072ca5d4ba0d56 (diff)
downloaddotfiles-515b693e6171b456ebc1dc7d1bd469c13c6b386d.tar.gz
New: bin/dmenu_playerctl
-rwxr-xr-xbin/dmenu_playerctl30
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/dmenu_playerctl b/bin/dmenu_playerctl
new file mode 100755
index 0000000..cc4493a
--- /dev/null
+++ b/bin/dmenu_playerctl
@@ -0,0 +1,30 @@
+#!/bin/mksh
+
+select_player() {
+ echo $1 | tr ' ' '\n' | ${DMENU}
+}
+
+player_menu() {
+ PROMPT="$1:"
+ ARTIST=$(playerctl -p $1 metadata xesam:artist)
+ TITLE=$(playerctl -p $1 metadata xesam:title)
+ if [ -n "$ARTIST" -a -n "$TITLE" ]; then
+ PROMPT="$PROMPT $ARTIST - $TITLE"
+ fi
+ if [ $(playerctl -p $1 status) == "Playing" ]; then
+ CMDS="Pause\n"
+ else
+ CMDS="Play\n"
+ fi
+ CMDS+="Stop\nNext\nPrevious"
+ ret=$(echo $CMDS | ${DMENU} -p "$PROMPT" -i | tr '[A-Z]' '[a-z]')
+ [ $ret ] && playerctl -p $1 $ret
+}
+
+: ${DMENU:=dmenu}
+: ${PLAYER:=$(playerctl -l)}
+case "$(echo ${PLAYER} | wc -w)" in
+ 0) echo "No player running" && exit ;;
+ 1) player_menu "$PLAYER" ;;
+ *) player_menu $(select_player "$PLAYER") ;;
+esac