dotfiles

configuration files
git clone https://pi.duncano.de/git/dotfiles.git
Log | Files | Refs | README

commit 7f073a21c11dd42150833257f4a75f2845d42708
parent 515b693e6171b456ebc1dc7d1bd469c13c6b386d
Author: Duncaen <mail@duncano.de>
Date:   Sat, 16 May 2015 15:54:54 +0200

bin/dmenu_playerctl: add volume menu and clean up

Diffstat:
bin/dmenu_playerctl | 50+++++++++++++++++++++++++++++++++++++-------------
1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/bin/dmenu_playerctl b/bin/dmenu_playerctl @@ -4,21 +4,45 @@ 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" +prompt() { + a=$(playerctl -p $1 metadata xesam:artist) + t=$(playerctl -p $1 metadata xesam:title) + if [ -n "$a" -a -n "$t" ]; then + echo "$1: $a - $t" else - CMDS="Play\n" + echo "$1:" fi - CMDS+="Stop\nNext\nPrevious" - ret=$(echo $CMDS | ${DMENU} -p "$PROMPT" -i | tr '[A-Z]' '[a-z]') - [ $ret ] && playerctl -p $1 $ret +} + +play_pause() { + [ $(playerctl -p $1 status) == "Playing" ] && echo "Pause" || echo "Play" +} + +player_menu() { + CMDS="$(play_pause $1)\nStop\nNext\nPrevious\nVolume" + ret=$(echo $CMDS | ${DMENU} -p "$(prompt $1)" -i | tr '[A-Z]' '[a-z]') + case "$ret" in + play|pause|next|previous) playerctl -p $1 $ret ;; + volume) volume_menu $1 ;; + esac +} + +volume_menu() { + while : + do + VOL=$(echo "$(playerctl -p $1 volume) * 100" | bc) + VOL=${VOL%.*} + ret=$(echo "Up\nDown" | ${DMENU} -p "$1: $VOL" -i | tr '[A-Z]' '[a-z]') + case "$ret" in + up) playerctl -p $1 volume $(echo "($VOL + 5) / 100" | bc -l) ;; + down) playerctl -p $1 volume $(echo "($VOL - 5) / 100" | bc -l) ;; + *) + [ -z "$ret" ] && break + [ -n "$(echo $ret | tr -d '[[:digit:]]')" ] && break + playerctl -p $1 volume $(echo "$ret / 100" | bc -l) + ;; + esac + done } : ${DMENU:=dmenu}