Last active
August 30, 2017 07:05
-
-
Save hashhar/1b4ce32feffc39344fd2a77335b187c6 to your computer and use it in GitHub Desktop.
MPD Status 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/bash | |
i3status | while : | |
do | |
read line | |
printf -v mpd_song "%q" "$(mpc current -f "[[%albumartist%|%artist% - ]%title%]")" | |
# printf -v sets the variable to '' in case of empty assignment | |
if [[ "$mpd_song" == "''" ]]; then | |
printf -v mpd_song "%q" "$(basename "$(mpc current -f "%file%")")" | |
fi | |
status="$(mpc status)" | |
mpd_status="$(echo "$status" | tail -2 | head -1 | cut -d' ' -f1 | tr -d '[]')" | |
flag=1 | |
case "$mpd_status" in | |
"playing" ) | |
color="#00AAAA" ;; | |
"paused" ) | |
color="#AAAA00" ;; | |
* ) | |
flag=0 ;; | |
esac | |
if (( flag == 1 )); then | |
echo "$line" | sed 's|{\"name|{\"name\":\"music\",\"color\": \"'"$color"'\",\"full_text\":\" '"$mpd_song"'\"},{\"name|' || exit 1 | |
continue | |
else | |
echo -n "$line" || exit 1 | |
continue | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revised the script to be more resilient in all possible states of mpd server (provided the server is running).