Skip to content

Instantly share code, notes, and snippets.

@petehalverson
Last active November 12, 2016 14:30
Show Gist options
  • Save petehalverson/83c4ae282244fd6aef442c31e348d29d to your computer and use it in GitHub Desktop.
Save petehalverson/83c4ae282244fd6aef442c31e348d29d to your computer and use it in GitHub Desktop.
Docker environment manager. Shortcut for setting docker environment with bash completion
# 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
@petehalverson
Copy link
Author

petehalverson commented Nov 12, 2016

Checks if docker-machine is available and copies new docker environment IP to clipboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment