From a694904e91391b71df23f4d815d973c2a0c89f5a Mon Sep 17 00:00:00 2001 From: Oded Arbel Date: Mon, 21 Aug 2023 19:42:32 +0300 Subject: [PATCH] Stop slowing bash init by caching plugins path slowly Fixes issue #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 (cherry picked from commit 1da67be9caf37a4f0b297cfd41da3ab41c2bd2c7) Signed-off-by: Sebastiaan van Stijn --- contrib/completion/bash/docker | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 245d70071a..8828599e40 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -1184,7 +1184,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 @@ -5572,7 +5575,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%%.*}