Skip to content

Instantly share code, notes, and snippets.

@ku1ik
Created February 1, 2012 12:55
Show Gist options
  • Save ku1ik/1716868 to your computer and use it in GitHub Desktop.
Save ku1ik/1716868 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
HOST="192.168.20.205"
SHELL_NAME=$(basename $SHELL)
log() {
echo -e "\x1b[1;32m$1\x1b[0m"
}
if [[ "$1" == "play" ]]; then
if [[ -n "$2" ]]; then
mpc -h $HOST clear >/dev/null
mpc -h $HOST add "$2"
fi
log "Playing: $(mpc -h $HOST playlist)"
mpc -h $HOST play >/dev/null
elif [[ "$1" == "stop" ]]; then
mpc -h $HOST stop
log "Stopped."
elif [[ "$1" == "ls" ]]; then
log "Library:"
echo
mpc -h $HOST listall
elif [[ "$1" == "upload" ]]; then
scp "$2" "rubydev@$HOST:~/Music/"
mpc -h $HOST update
mpc -h $HOST clear
mpc -h $HOST findadd filename $(basename "$2")
"$0" play
elif [[ "$1" == "update" ]]; then
log "Updating..."
exec curl https://raw.github.com/gist/1716868/gistfile1.sh -o "$0"
elif [[ "$1" == "autocompletion" ]]; then
if [[ $SHELL_NAME == "bash" ]]; then
cat <<EOS
_cygan_comp() {
local cur=\${COMP_WORDS[COMP_CWORD]}
if [[ "\$COMP_CWORD" == 1 ]]; then
local names="play stop ls upload update"
COMPREPLY=( \$(compgen -W "\$names" -- \$cur) )
elif [[ "\$COMP_CWORD" == 2 && "\${COMP_WORDS[1]}" == "play" ]]; then
local names=\$(mpc -h $HOST listall)
COMPREPLY=( \$(compgen -W "\$names" -- \$cur) )
fi
}
complete -F _cygan_comp $(basename $0)
EOS
elif [[ $SHELL_NAME == "zsh" ]]; then
cat <<EOS
_cygan_comp() {
local word words
read -cA words
word="\${words[2]}"
if [ "\${#words}" -eq 2 ]; then
reply=(play stop ls upload update)
elif [ "\${#words}" -eq 3 ] && [ "\$word" = "play" ]; then
reply=(\`mpc -h $HOST listall\`)
fi
}
compctl -K _cygan_comp $(basename $0)
EOS
fi
else
echo "usage: $0 { play <NAME> | stop | ls | upload <LOCAL_FILE> | update | autocompletion }"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment