Last active
February 27, 2018 17:26
-
-
Save Smudge3806/134402a5af2d56395a11196d0ef64818 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
#!/bin/bash | |
function download_git_completion | |
{ | |
TARGET=$1 | |
if [ ! -r $TARGET ]; then | |
GIT_VERSION=`git --version | awk '{print $3}'` | |
curl --silent "https://raw.githubusercontent.com/git/git/v$GIT_VERSION/contrib/completion/git-completion.bash" \ | |
--output $TARGET | |
fi | |
unset GIT_VERSION TARGET | |
} | |
function download_docker_ce_completion | |
{ | |
TARGET=$1 | |
if [ ! -r $TARGET ]; then | |
DOCKER_CE_VERSION=`docker --version | awk 'NR==1{print $NF}'` | |
curl -L --silent "https://raw.githubusercontent.com/docker/docker-ce/$DOCKER_CE_VERSION/components/cli/contrib/completion/bash/docker" \ | |
--output $TARGET | |
fi | |
unset DOCKER_CE_VERSION TARGET | |
} | |
function download_docker_compose_completion | |
{ | |
TARGET=$1 | |
if [ ! -r $TARGET ]; then | |
DOCKER_COMPOSE_VERSION=`docker-compose --version | awk 'NR==1{print $NF}'` | |
curl -L --silent "https://raw.githubusercontent.com/docker/compose/$DOCKER_COMPOSE_VERSION/contrib/completion/bash/docker-compose" \ | |
--output $TARGET | |
fi | |
unset DOCKER_COMPOSE_VERSION TARGET | |
} | |
function download_docker_machine_completion | |
{ | |
TARGET=$1 | |
if [ ! -r $TARGET ]; then | |
DOCKER_MACHINE_VERSION=`docker-machine --version | awk 'NR==1{print $NF}'` | |
curl -L --silent "https://raw.githubusercontent.com/docker/machine/$DOCKER_MACHINE_VERSION/contrib/completion/bash/docker-machine.bash" \ | |
--output $TARGET | |
fi | |
unset DOCKER_MACHINE_VERSION TARGET | |
} | |
# haz bash_completion? | |
if [ -r /etc/bash_completion ]; then | |
# Get git completion if not local | |
download_git_completion /etc/bash_completion.d/git | |
# Get docker-ce completion if not local | |
download_docker_ce_completion /etc/bash_completion.d/docker | |
# Get docker-compose completion if not local | |
download_docker_compose_completion /etc/bash_completion.d/docker-compose | |
# Get docker-machine completion if not local | |
download_docker_machine_completion /etc/bash_completion.d/docker-machine | |
# Load bashj_completion | |
. /etc/bash_completion | |
elif command -v brew >/dev/null 2>&1 ; then | |
BREW_INSTALL_LOC=$(brew --prefix) | |
# Get bash_completion with brew if not local | |
[ ! -r $BREW_INSTALL_LOC/etc/bash_completion ] && brew install bash-completion | |
# Get packer completion if packer is installed but completion is not present | |
[ -r $BREW_INSTALL_LOC/bin/packer ] && [ ! -r $BREW_INSTALL_LOC/etc/bash_completion.d/packer ] && brew install packer-completion | |
# Get git completion if not local | |
download_git_completion $BREW_INSTALL_LOC/etc/bash_completion.d/git | |
# Get docker-ce completion if not local | |
download_docker_ce_completion $BREW_INSTALL_LOC/etc/bash_completion.d/docker | |
# Get docker-compose completion if not local | |
download_docker_compose_completion $BREW_INSTALL_LOC/etc/bash_completion.d/docker-compose | |
# Get docker-machine completion if not local | |
download_docker_machine_completion $BREW_INSTALL_LOC/etc/bash_completion.d/docker-machine | |
# Load bash-completion | |
[ -r $BREW_INSTALL_LOC/etc/bash_completion ] && . $BREW_INSTALL_LOC/etc/bash_completion | |
unset BREW_INSTALL_LOC | |
else | |
echo "Can't find brew or /etc/bash_completion" | |
fi | |
unset -f download_{git,docker_compose,docker_machine}_completion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment