Skip to content

Instantly share code, notes, and snippets.

@hashhar
Last active August 30, 2017 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashhar/1b4ce32feffc39344fd2a77335b187c6 to your computer and use it in GitHub Desktop.
Save hashhar/1b4ce32feffc39344fd2a77335b187c6 to your computer and use it in GitHub Desktop.
MPD Status in i3status
#!/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
@hashhar
Copy link
Author

hashhar commented Aug 30, 2017

Revised the script to be more resilient in all possible states of mpd server (provided the server is running).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment