Last active
August 25, 2017 08:12
-
-
Save fritschy/3eeb5aa5cac65e72bf8e06f37ab3c0e2 to your computer and use it in GitHub Desktop.
Simple mpd status for use in i3status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/busybox sh | |
| set -eu | |
| # reset | |
| export LD_LIBRARY_PATH= | |
| # call mpc once | |
| STATUS=$(mpc|tr -s ' ') | |
| FIRST=$(echo "$STATUS" | head -n1) | |
| SECOND=$(echo "$STATUS" | tail -n+2 | head -n1) | |
| # clip $1 to $2 characters | |
| clip() { | |
| x="$1" | |
| l=$(echo "$x" | wc -c) | |
| if [ "$l" -gt $2 ] | |
| then | |
| x=$(echo "$x" | head -c 30)... | |
| fi | |
| echo "$x" | |
| } | |
| # echo title | |
| title() { | |
| l=$(echo "$FIRST" | wc -c) | |
| x="$FIRST" | |
| if [ "$l" -gt 33 ] | |
| then | |
| x=$(echo $FIRST | sed -e 's/^.* - //1') | |
| x=$(clip "$x" 30) | |
| fi | |
| echo "$x" | |
| } | |
| # position in track in percent | |
| percent=$(echo "$SECOND" | cut -d' ' -f4) | |
| # play/pause(/stop) | |
| pp="◼" | |
| case "$(echo "$SECOND" | cut -d' ' -f1)" in | |
| "[playing]") | |
| pp="▶" | |
| ;; | |
| "[paused]") | |
| pp="Ⅱ" | |
| ;; | |
| esac | |
| echo "$pp $percent $(title)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment