Skip to content

Commit

Permalink
Stop slowing bash init by caching plugins path slowly
Browse files Browse the repository at this point in the history
Fixes issue docker#3889 by only loading docker plugins path when needed: if it is fast enough than it shouldn't be a problem to do this on demand; OTOH if it is slow then we shouldn't do this during *every* bash session initialization, regardless if docker completion will be needed or not.

Signed-off-by: Oded Arbel <oded@geek.co.il>
  • Loading branch information
guss77 committed Aug 23, 2023
1 parent cdabfa2 commit 1da67be
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions contrib/completion/bash/docker
Expand Up @@ -1142,7 +1142,10 @@ __docker_complete_user_group() {
fi
}

DOCKER_PLUGINS_PATH=$(docker info --format '{{range .ClientInfo.Plugins}}{{.Path}}:{{end}}')
__docker_plugins_path() {
local docker_plugins_path=$(docker info --format '{{range .ClientInfo.Plugins}}{{.Path}}:{{end}}')
echo "${docker_plugins_path//:/ }"
}

__docker_complete_plugin() {
local path=$1
Expand Down Expand Up @@ -5504,7 +5507,7 @@ _docker() {
# Create completion functions for all registered plugins
local known_plugin_commands=()
local plugin_name=""
for plugin_path in ${DOCKER_PLUGINS_PATH//:/ }; do
for plugin_path in $(__docker_plugins_path); do
plugin_name=$(basename "$plugin_path" | sed 's/ *$//')
plugin_name=${plugin_name#docker-}
plugin_name=${plugin_name%%.*}
Expand Down

0 comments on commit 1da67be

Please sign in to comment.