fix(docker): use `docker --version` instead of `docker version`
`docker version` subcommand is able to return both docker client and
docker daemon information. To get a daemon version, it connects to a
possibly remote daemon. If the remote daemon is not accessible, the
client waits for some time, until it gets interrupted by timeout.
As a result we can have a docker client running in background. When zsh
session is rather short, a terminal application (iTerm2) starts asking
if that background docker process should be stopped.
On the other hand, to get a docker client version only, we can use
`docker --version` instead. It does not connect to a daemon.
Closes #11780
Diff
1diff --git a/plugins/docker/docker.plugin.zsh b/plugins/docker/docker.plugin.zsh
2index 434b1fc6047d5824dbc7f3ccb50c2e5302cb08fc..3abce64669b484240678883da12646bace4a8a36 100644
3--- a/plugins/docker/docker.plugin.zsh
4+++ b/plugins/docker/docker.plugin.zsh
5@@ -37,8 +37,10 @@ if (( ! $+commands[docker] )); then
6 fi
7 8 {
9+ # docker version returns `Docker version 24.0.2, build cb74dfcd85`
10+ # with `s:,:` remove the comma after the version, and select third word of it
11+ local _docker_version=${${(s:,:z)"$(command docker --version)"}[3]}
12 # `docker completion` is only available from 23.0.0 on
13- local _docker_version=$(command docker version --format '{{.Client.Version}}' 2>/dev/null)
14 if is-at-least 23.0.0 $_docker_version; then
15 # If the completion file doesn't exist yet, we need to autoload it and
16 # bind it to `docker`. Otherwise, compinit will have already done that.