Last active
November 12, 2016 14:30
-
-
Save petehalverson/83c4ae282244fd6aef442c31e348d29d to your computer and use it in GitHub Desktop.
Docker environment manager. Shortcut for setting docker environment with bash completion
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
# add to .bashrc, .bash_profile, ~/.profile | |
dockenv() { | |
command -v "docker-machine" >/dev/null 2>&1 && { | |
if [ $1 = 'unset' -o $1 = '-u' ]; then | |
eval $(docker-machine env -u) | |
else | |
eval $(docker-machine env "$1") | |
if ! [ $1 = 'unset' -o $1 = '-u' ]; then | |
docker-machine ip $1 | tr -d '\n' | pbcopy | |
fi | |
fi | |
} || { echo >&2 "Error: \`docker-machine\` is required but not installed. Aborting..."; } | |
} | |
_dockenv() { | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
COMPREPLY=( $(compgen -W "$(docker-machine ls -q)" -- $cur) ) | |
} | |
complete -o default -F _dockenv dockenv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checks if
docker-machine
is available and copies new docker environment IP to clipboard