Skip to content

Instantly share code, notes, and snippets.

@hailwood
Last active January 2, 2018 07:37
Show Gist options
  • Save hailwood/beb377c588c41c9e93bacdca0fb3ff1d to your computer and use it in GitHub Desktop.
Save hailwood/beb377c588c41c9e93bacdca0fb3ff1d to your computer and use it in GitHub Desktop.
docker-connect/docker-ip function and autocomplete
#Setup the autocomplete
fpath=(~/.zsh/completion $fpath) #assuming the _docker-connect file is stored at ~/.zsh/completion/_docker-connect
autoload -Uz compinit && compinit -i
#The actual functions
docker-connect () {
docker exec -i -t $1 /bin/bash
}
docker-ip () {
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $1
}
#compdef docker-connect
_docker-connect() {
local opts=$(docker ps --format '{{.Names}}')
while IFS= read -r line ; do compadd $line; done <<< "$opts"
}
_docker-connect "$@"
#compdef docker-ip
_docker-ip() {
local opts=$(docker ps --format '{{.Names}}')
while IFS= read -r line ; do compadd $line; done <<< "$opts"
}
_docker-ip "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment