Last active
February 26, 2016 06:04
-
-
Save DanielFGray/877e037c1375894c253e to your computer and use it in GitHub Desktop.
This file contains 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
#!/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