Skip to content

Instantly share code, notes, and snippets.

@cmizzi
Created September 11, 2018 08:58
Show Gist options
  • Save cmizzi/5f372b672f65823eed52fa04db1b953f to your computer and use it in GitHub Desktop.
Save cmizzi/5f372b672f65823eed52fa04db1b953f to your computer and use it in GitHub Desktop.
Add `dl` command to access service/container logs easily
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