diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2023-11-04 18:38:46 -0700 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2023-11-04 18:38:46 -0700 |
commit | 4d908094fdc2a0c0e9a0a072eba213fab7adef43 (patch) | |
tree | 7c17e70bcdeebbe96c84d849bdf17882007480d8 /plugins/docker/docker.plugin.zsh | |
parent | 4b0bbc0b263a150eb9a9b59f196914629be06a9b (diff) | |
parent | 632ed413a9ce62747ded83d7736491b081be4b49 (diff) | |
download | zsh-master.tar.gz zsh-master.tar.bz2 zsh-master.zip |
Diffstat (limited to 'plugins/docker/docker.plugin.zsh')
-rw-r--r-- | plugins/docker/docker.plugin.zsh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh index 8684a9785..7e657f2df 100644 --- a/plugins/docker/docker.plugin.zsh +++ b/plugins/docker/docker.plugin.zsh @@ -31,3 +31,32 @@ alias dvls='docker volume ls' alias dvprune='docker volume prune' alias dxc='docker container exec' alias dxcit='docker container exec -it' + +if (( ! $+commands[docker] )); then + return +fi + +# Standarized $0 handling +# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" +0="${${(M)0:#/*}:-$PWD/$0}" + +# 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` is only available from 23.0.0 on + # docker version returns `Docker version 24.0.2, build cb74dfcd85` + # with `s:,:` remove the comma after the version, and select third word of it + if zstyle -t ':omz:plugins:docker' legacy-completion || \ + ! is-at-least 23.0.0 ${${(s:,:z)"$(command docker --version)"}[3]}; then + command cp "${0:h}/completions/_docker" "$ZSH_CACHE_DIR/completions/_docker" + else + command docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker" + fi +} &| |