summaryrefslogtreecommitdiff
path: root/plugins/docker
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/docker')
-rw-r--r--plugins/docker/README.md19
-rw-r--r--plugins/docker/completions/_docker (renamed from plugins/docker/_docker)11
-rw-r--r--plugins/docker/docker.plugin.zsh33
3 files changed, 58 insertions, 5 deletions
diff --git a/plugins/docker/README.md b/plugins/docker/README.md
index 512b5d17c..0bc24b54a 100644
--- a/plugins/docker/README.md
+++ b/plugins/docker/README.md
@@ -30,6 +30,19 @@ 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
+```
+
+### For Podman's Docker wrapper users
+
+If you use Podman's Docker wrapper, you need to enable legacy completion. See above section.
+
## Aliases
| Alias | Command | Description |
@@ -42,6 +55,7 @@ file**, but be aware of the side effects:
| dii | `docker image inspect` | Display detailed information on one or more images |
| dils | `docker image ls` | List docker images |
| dipu | `docker image push` | Push an image or repository to a remote registry |
+| dipru | `docker image prune -a` | Remove all images not referenced by any container |
| dirm | `docker image rm` | Remove one or more images |
| dit | `docker image tag` | Add a name and tag to a particular image |
| dlo | `docker container logs` | Fetch the logs of a docker container |
@@ -52,15 +66,18 @@ file**, but be aware of the side effects:
| dnls | `docker network ls` | List all networks the engine daemon knows about, including those spanning multiple hosts |
| dnrm | `docker network rm` | Remove one or more networks |
| dpo | `docker container port` | List port mappings or a specific mapping for the container |
+| dps | `docker ps` | List all the running docker containers |
+| dpsa | `docker ps -a` | List all running and stopped containers |
| dpu | `docker pull` | Pull an image or a repository from a registry |
| dr | `docker container run` | Create a new container and start it using the specified command |
| drit | `docker container run -it` | Create a new container and start it in an interactive shell |
| 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 |
+| dsts | `docker stats` | Display real-time streaming statistics for containers |
| dtop | `docker top` | Display the running processes of a container |
| dvi | `docker volume inspect` | Display detailed information about one or more volumes |
| dvls | `docker volume ls` | List all the volumes known to docker |
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..5268f6cd6 100644
--- a/plugins/docker/docker.plugin.zsh
+++ b/plugins/docker/docker.plugin.zsh
@@ -6,6 +6,7 @@ alias dib='docker image build'
alias dii='docker image inspect'
alias dils='docker image ls'
alias dipu='docker image push'
+alias dipru='docker image prune -a'
alias dirm='docker image rm'
alias dit='docker image tag'
alias dlo='docker container logs'
@@ -16,6 +17,8 @@ alias dni='docker network inspect'
alias dnls='docker network ls'
alias dnrm='docker network rm'
alias dpo='docker container port'
+alias dps='docker ps'
+alias dpsa='docker ps -a'
alias dpu='docker pull'
alias dr='docker container run'
alias drit='docker container run -it'
@@ -25,9 +28,39 @@ alias dst='docker container start'
alias drs='docker container restart'
alias dsta='docker stop $(docker ps -q)'
alias dstp='docker container stop'
+alias dsts='docker stats'
alias dtop='docker top'
alias dvi='docker volume inspect'
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
+
+# Standardized $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 | tee "$ZSH_CACHE_DIR/completions/_docker" > /dev/null
+ fi
+} &|