Last active
January 2, 2018 07:37
-
-
Save hailwood/beb377c588c41c9e93bacdca0fb3ff1d to your computer and use it in GitHub Desktop.
docker-connect/docker-ip function and autocomplete
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
#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 | |
} |
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
#compdef docker-connect | |
_docker-connect() { | |
local opts=$(docker ps --format '{{.Names}}') | |
while IFS= read -r line ; do compadd $line; done <<< "$opts" | |
} | |
_docker-connect "$@" |
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
#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