mirror of https://github.com/docker/cli.git
Add bash completion for available plugins
Signed-off-by: CrazyMax <github@crazymax.dev>
(cherry picked from commit aa0aa4a6dc
)
This commit is contained in:
parent
3825ed5f7e
commit
928e470879
|
@ -1184,6 +1184,29 @@ __docker_complete_user_group() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DOCKER_PLUGINS_PATH=$(docker info --format '{{range .ClientInfo.Plugins}}{{.Path}}:{{end}}')
|
||||||
|
|
||||||
|
__docker_complete_plugin() {
|
||||||
|
local path=$1
|
||||||
|
local completionCommand="__completeNoDesc"
|
||||||
|
local resultArray=($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]*$')
|
||||||
|
|
||||||
|
# if result empty, just use filename completion as fallback
|
||||||
|
if [ -z "$result" ]; then
|
||||||
|
_filedir
|
||||||
|
else
|
||||||
|
COMPREPLY=( $(compgen -W "${result}" -- "${current-}") )
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
_docker_docker() {
|
_docker_docker() {
|
||||||
# global options that may appear after the docker command
|
# global options that may appear after the docker command
|
||||||
local boolean_options="
|
local boolean_options="
|
||||||
|
@ -5477,23 +5500,6 @@ _docker_wait() {
|
||||||
_docker_container_wait
|
_docker_container_wait
|
||||||
}
|
}
|
||||||
|
|
||||||
COMPOSE_PLUGIN_PATH=$(docker info --format '{{range .ClientInfo.Plugins}}{{if eq .Name "compose"}}{{.Path}}{{end}}{{end}}')
|
|
||||||
|
|
||||||
_docker_compose() {
|
|
||||||
local completionCommand="__completeNoDesc"
|
|
||||||
local resultArray=($COMPOSE_PLUGIN_PATH $completionCommand compose)
|
|
||||||
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") )
|
|
||||||
}
|
|
||||||
|
|
||||||
_docker() {
|
_docker() {
|
||||||
local previous_extglob_setting=$(shopt -p extglob)
|
local previous_extglob_setting=$(shopt -p extglob)
|
||||||
shopt -s extglob
|
shopt -s extglob
|
||||||
|
@ -5563,11 +5569,16 @@ _docker() {
|
||||||
wait
|
wait
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Create completion functions for all registered plugins
|
||||||
local known_plugin_commands=()
|
local known_plugin_commands=()
|
||||||
|
local plugin_name=""
|
||||||
if [ -f "$COMPOSE_PLUGIN_PATH" ] ; then
|
for plugin_path in ${DOCKER_PLUGINS_PATH//:/ }; do
|
||||||
known_plugin_commands+=("compose")
|
plugin_name=$(basename "$plugin_path" | sed 's/ *$//')
|
||||||
fi
|
plugin_name=${plugin_name#docker-}
|
||||||
|
plugin_name=${plugin_name%%.*}
|
||||||
|
eval "_docker_${plugin_name}() { __docker_complete_plugin \"${plugin_path}\"; }"
|
||||||
|
known_plugin_commands+=(${plugin_name})
|
||||||
|
done
|
||||||
|
|
||||||
local experimental_server_commands=(
|
local experimental_server_commands=(
|
||||||
checkpoint
|
checkpoint
|
||||||
|
|
Loading…
Reference in New Issue