summaryrefslogtreecommitdiff
path: root/plugins/docker
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/docker')
-rw-r--r--plugins/docker/README.md11
-rw-r--r--plugins/docker/completions/_docker (renamed from plugins/docker/_docker)11
-rw-r--r--plugins/docker/docker.plugin.zsh29
3 files changed, 46 insertions, 5 deletions
diff --git a/plugins/docker/README.md b/plugins/docker/README.md
index 512b5d17c..0ab2e41fb 100644
--- a/plugins/docker/README.md
+++ b/plugins/docker/README.md
@@ -30,6 +30,15 @@ file**, but be aware of the side effects:
> zstyle ':completion:*:*:docker-*:*' option-stacking yes
> ```
+### Use old-style completion
+
+If the current completion does not work well for you, you can enable legacy completion instead with the
+following setting. See https://github.com/ohmyzsh/ohmyzsh/issues/11789 for more information.
+
+```zsh
+zstyle ':omz:plugins:docker' legacy-completion yes
+```
+
## Aliases
| Alias | Command | Description |
@@ -58,7 +67,7 @@ file**, but be aware of the side effects:
| drm | `docker container rm` | Remove the specified container(s) |
| drm! | `docker container rm -f` | Force the removal of a running container (uses SIGKILL) |
| dst | `docker container start` | Start one or more stopped containers |
-| drs | `docker container restart` | Restart one or more containers
+| drs | `docker container restart` | Restart one or more containers |
| dsta | `docker stop $(docker ps -q)` | Stop all running containers |
| dstp | `docker container stop` | Stop one or more running containers |
| dtop | `docker top` | Display the running processes of a container |
diff --git a/plugins/docker/_docker b/plugins/docker/completions/_docker
index e6a12d774..466b09d94 100644
--- a/plugins/docker/_docker
+++ b/plugins/docker/completions/_docker
@@ -602,6 +602,7 @@ __docker_container_subcommand() {
opts_create_run=(
"($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)"
"($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: "
+ "($help)*--annotation=[Add an annotation to the container (passed through to the OCI runtime)]:annotations: "
"($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: "
"($help)*--cap-add=[Add Linux capabilities]:capability: "
"($help)*--cap-drop=[Drop Linux capabilities]:capability: "
@@ -662,7 +663,7 @@ __docker_container_subcommand() {
"($help)*--ulimit=[ulimit options]:ulimit: "
"($help)--userns=[Container user namespace]:user namespace:(host)"
"($help)--tmpfs[mount tmpfs]"
- "($help)*-v[Bind mount a volume]:volume: "
+ "($help)*-v[Bind mount a volume]:volume:_directories -W / -P '/' -S '\:' -r '/ '"
"($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)"
"($help)*--volumes-from=[Mount volumes from the specified container]:volume: "
"($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
@@ -2527,6 +2528,8 @@ __docker_volume_subcommand() {
(prune)
_arguments $(__docker_arguments) \
$opts_help \
+ "($help -a --all)"{-a,--all}"[Remove all unused local volumes, not just anonymous ones]" \
+ "($help)*--filter=[Filter values]:filter:__docker_complete_prune_filters" \
"($help -f --force)"{-f,--force}"[Do not prompt for confirmation]" && ret=0
;;
(rm)
@@ -2765,8 +2768,8 @@ __docker_subcommand() {
"($help)--live-restore[Enable live restore of docker when containers are still running]" \
"($help)--log-driver=[Default driver for container logs]:logging driver:__docker_complete_log_drivers" \
"($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_complete_log_options" \
- "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \
- "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \
+ "($help)--max-concurrent-downloads[Set the max concurrent downloads]" \
+ "($help)--max-concurrent-uploads[Set the max concurrent uploads]" \
"($help)--max-download-attempts[Set the max download attempts for each pull]" \
"($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \
"($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \
@@ -2774,7 +2777,7 @@ __docker_subcommand() {
"($help)--raw-logs[Full timestamps without ANSI coloring]" \
"($help)*--registry-mirror=[Preferred registry mirror]:registry mirror: " \
"($help)--seccomp-profile=[Path to seccomp profile]:path:_files -g \"*.json\"" \
- "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \
+ "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(btrfs devicemapper overlay2 vfs zfs)" \
"($help)--selinux-enabled[Enable selinux support]" \
"($help)--shutdown-timeout=[Set the shutdown timeout value in seconds]:time: " \
"($help)*--storage-opt=[Storage driver options]:storage driver options: " \
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
+} &|