Skip to content

Instantly share code, notes, and snippets.

@kostix
Created September 21, 2021 18:27
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 kostix/81bb96f8dae4746aede8e4d77904a723 to your computer and use it in GitHub Desktop.
Save kostix/81bb96f8dae4746aede8e4d77904a723 to your computer and use it in GitHub Desktop.
mpc wrapper with a bit of interactivity
#!/bin/sh
set -e -u
mpc=/usr/bin/mpc
if [ $# -lt 1 ]; then
"$mpc" "$@"
exit $?
fi
select()
{
if [ $# -eq 0 ]; then
"$mpc" lsplaylists | fzf
else
terms="$@"
"$mpc" lsplaylists | fzf -q "$terms"
fi
}
enumerated_playlist()
{
"$mpc" playlist | {
i=1
while read line; do
printf "%d\t%s\n" $i "$line"
i=$((i+1))
done
}
}
case "$1" in
playlist)
enumerated_playlist
;;
iload)
shift
playlist=`select "$@"` || return 0
test -z "$playlist" || break
"$mpc" load "$playlist"
;;
ireplace|irep)
shift
playlist=`select "$@"` || return 0
test -z "$playlist" || break
"$mpc" clear
"$mpc" load "$playlist"
"$mpc" play 1
;;
replace|reload)
shift
"$mpc" clear && "$mpc" load "$@"
;;
*)
"$mpc" "$@"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment