Diff
1diff --git a/plugins/docker/README.md b/plugins/docker/README.md
2index 512b5d17ce601e3e2959ca2a991c9afdce97ad2a..0ab2e41fb49f0599fdfeb3785617c7ec686da253 100644
3--- a/plugins/docker/README.md
4+++ b/plugins/docker/README.md
5@@ -30,6 +30,15 @@ file**, but be aware of the side effects:
6 > zstyle ':completion:*:*:docker-*:*' option-stacking yes
7 > ```
8
9+### Use old-style completion
10+
11+If the current completion does not work well for you, you can enable legacy completion instead with the
12+following setting. See https://github.com/ohmyzsh/ohmyzsh/issues/11789 for more information.
13+
14+```zsh
15+zstyle ':omz:plugins:docker' legacy-completion yes
16+```
17+
18 ## Aliases
19
20 | Alias | Command | Description |
21@@ -58,7 +67,7 @@ file**, but be aware of the side effects:
22 | drm | `docker container rm` | Remove the specified container(s) |
23 | drm! | `docker container rm -f` | Force the removal of a running container (uses SIGKILL) |
24 | dst | `docker container start` | Start one or more stopped containers |
25-| drs | `docker container restart` | Restart one or more containers
26+| drs | `docker container restart` | Restart one or more containers |
27 | dsta | `docker stop $(docker ps -q)` | Stop all running containers |
28 | dstp | `docker container stop` | Stop one or more running containers |
29 | dtop | `docker top` | Display the running processes of a container |
30diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh
31index 7777048a380892b487757689f21364b79d397e80..7e657f2dfc266c3d7534b3473a3c03ce34918166 100644
32--- a/plugins/docker/docker.plugin.zsh
33+++ b/plugins/docker/docker.plugin.zsh
34@@ -41,21 +41,22 @@ fi
35 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
36 0="${${(M)0:#/*}:-$PWD/$0}"
37
38+# If the completion file doesn't exist yet, we need to autoload it and
39+# bind it to `docker`. Otherwise, compinit will have already done that.
40+if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then
41+ typeset -g -A _comps
42+ autoload -Uz _docker
43+ _comps[docker]=_docker
44+fi
45+
46 {
47+ # `docker completion` is only available from 23.0.0 on
48 # docker version returns `Docker version 24.0.2, build cb74dfcd85`
49 # with `s:,:` remove the comma after the version, and select third word of it
50- local _docker_version=${${(s:,:z)"$(command docker --version)"}[3]}
51- # `docker completion` is only available from 23.0.0 on
52- if is-at-least 23.0.0 $_docker_version; then
53- # If the completion file doesn't exist yet, we need to autoload it and
54- # bind it to `docker`. Otherwise, compinit will have already done that.
55- if [[ ! -f "$ZSH_CACHE_DIR/completions/_docker" ]]; then
56- typeset -g -A _comps
57- autoload -Uz _docker
58- _comps[docker]=_docker
59- fi
60- command docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker"
61- else
62- command cp "${0:h}/completions/_docker" "$ZSH_CACHE_DIR/completions/_docker"
63+ if zstyle -t ':omz:plugins:docker' legacy-completion || \
64+ ! is-at-least 23.0.0 ${${(s:,:z)"$(command docker --version)"}[3]}; then
65+ command cp "${0:h}/completions/_docker" "$ZSH_CACHE_DIR/completions/_docker"
66+ else
67+ command docker completion zsh >| "$ZSH_CACHE_DIR/completions/_docker"
68 fi
69 } &|