Skip to content

Instantly share code, notes, and snippets.

@DanielFGray
Last active February 26, 2016 06:04
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 DanielFGray/877e037c1375894c253e to your computer and use it in GitHub Desktop.
Save DanielFGray/877e037c1375894c253e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
declare player=''
declare -a supported=( 'mpc' )
for x in "${supported[@]}"; do
if command -v "$x" &> /dev/null; then
player="$x"
break
fi
done
if [[ -z "$player" ]]; then
printf 1>&2 'no supported music player found\n'
printf 1>&2 ' fzmp currently supports: %s\n' "${supported[*]}"
exit 1
fi
if ! command -v fzf &> /dev/null; then
echo 'fzf not found' 1>&2
exit 1
fi
do_mpc() {
mapfile -t songs < <(mpc listall | sort -r | "$HOME/.fzf/fzf" --prompt='» ' --reverse -m -e +s +2)
if (( ${#songs[@]} > 0 )); then
printf '%s\n' "${songs[@]}" | mpc -q add # && [[ -n $1 ]]
index=$(mpc playlist | wc -l)
if (( ${#songs[@]} > 1 )); then
index=$(( $index - ${#songs[@]} + 1))
mpc -q random off
fi
mpc -q play "$index"
fi
}
case "$player" in
'mpc') do_mpc ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment