Created
September 11, 2018 08:58
-
-
Save cmizzi/5f372b672f65823eed52fa04db1b953f to your computer and use it in GitHub Desktop.
Add `dl` command to access service/container logs easily
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
dl() { | |
if [ "$1" = "service" ]; then | |
docker service logs -f --tail 100 $2 | |
exit 0 | |
fi; | |
docker logs -f --tail 100 $2 | |
} | |
__dl() { | |
local state | |
_arguments \ | |
"1: :->kind" \ | |
"*: :->containers" \ | |
case $state in | |
(kind) compadd "$@" service container ;; | |
(*) | |
if [ "$words[2]" = "service" ]; then | |
_arguments "*:services:($((docker info 2> /dev/null | grep -i 'swarm: active') && docker service ls -q --format '{{.Name}}'))" | |
else | |
_arguments "*:containers:($(docker ps -q --format '{{.Names}}'))" | |
fi; | |
;; | |
esac | |
} | |
compdef __dl dl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment