Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -5395,6 +5395,23 @@ _docker_wait() {
_docker_container_wait
}

BUILDX_PLUGIN_PATH=$(docker info --format '{{range .ClientInfo.Plugins}}{{if eq .Name "buildx"}}{{.Path}}{{end}}{{end}}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for a follow-up, but I think we should try to make it generic for plugins. We should call docker info only once and process the result, depending the plugin name.
It might be tricky though, so maybe for a follow-up 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. I will make it more generic to support all plugins. Keep you posted.


_docker_buildx() {
local completionCommand="__completeNoDesc"
local resultArray=($BUILDX_PLUGIN_PATH $completionCommand)
for value in "${words[@]:2}"; do
if [ -z "$value" ]; then
resultArray+=( "''" )
else
resultArray+=( "$value" )
fi
done
local result=$(eval "${resultArray[*]}" 2> /dev/null | grep -v '^:[0-9]*$')

COMPREPLY=( $(compgen -W "${result}" -- "${current-}") )
}

COMPOSE_PLUGIN_PATH=$(docker info --format '{{range .ClientInfo.Plugins}}{{if eq .Name "compose"}}{{.Path}}{{end}}{{end}}')

_docker_compose() {
Expand Down Expand Up @@ -5483,6 +5500,9 @@ _docker() {

local known_plugin_commands=()

if [ -f "$BUILDX_PLUGIN_PATH" ] ; then
known_plugin_commands+=("buildx")
fi
if [ -f "$COMPOSE_PLUGIN_PATH" ] ; then
known_plugin_commands+=("compose")
fi
Expand Down