Skip to content

Instantly share code, notes, and snippets.

@tg-x
Last active March 17, 2021 19:23
Show Gist options
  • Save tg-x/80544b73678670ebc689f99e0b2add6c to your computer and use it in GitHub Desktop.
Save tg-x/80544b73678670ebc689f99e0b2add6c to your computer and use it in GitHub Desktop.
x-mpc
#!/usr/bin/env zsh
# x-mpc console MPD client
# 1. shows history of played tracks
# useful for streams where history is not visible in regular clients
# 2. allows bookmarking favourite tracks by saving them to a file
fav=${MPD_FAV:-"$HOME/.mpd.fav"}
jobs=()
trap '((#jobs == 0)) || kill $jobs; exit' EXIT HUP TERM INT
current() {
echo -ne "\n\r[`date +%H:%M`] `mpc current`"
}
current
while mpc idle player playlist >/dev/null; do
current
sleep 1
done & jobs+=($!)
while read -k1 c; do
echo -ne '\b '
case "$c" in
'!') echo -n '<3'; (echo -n "`date '+%Y-%m-%d'` "; mpc current) >> "$fav" ;;
'<') (mpc play; mpc prev) >/dev/null ;;
'>') (mpc play; mpc next) >/dev/null ;;
's') echo -n '[ ]'; mpc stop >/dev/null ;;
'p') echo -n `mpc toggle | grep 'playing\|paused' | sed 's/.*playing.*/|>/; s/.*paused.*/||/'` ;;
'q') exit ;;
esac
done
kill $jobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment