fix(docker): only generate completion for docker >23 (#11754)

This commit is contained in:
Carlo Sala 2023-06-15 20:06:56 +02:00 committed by GitHub
parent 68f3ebb4de
commit 6bffaab290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,3 @@
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `docker`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then
typeset -g -A _comps
autoload -Uz _docker
_comps[docker]=_docker
fi
docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" &|
alias dbl='docker build' alias dbl='docker build'
alias dcin='docker container inspect' alias dcin='docker container inspect'
alias dcls='docker container ls' alias dcls='docker container ls'
@ -41,3 +31,22 @@ alias dvls='docker volume ls'
alias dvprune='docker volume prune' alias dvprune='docker volume prune'
alias dxc='docker container exec' alias dxc='docker container exec'
alias dxcit='docker container exec -it' alias dxcit='docker container exec -it'
if (( ! $+commands[docker] )); then
return
fi
{
# `docker completion` is only available from 23.0.0 on
local _docker_version=$(docker version --format '{{.Client.Version}}' 2>/dev/null)
if is-at-least 23.0.0 $_docker_version; then
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `docker`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then
typeset -g -A _comps
autoload -Uz _docker
_comps[docker]=_docker
fi
docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker"
fi
} &|