From 683e4bf0c4887b9f6fb37bddf03725dd5831ac01 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Wed, 29 Mar 2023 18:06:08 +0100 Subject: [PATCH] Fix plugin completion parsing for plugins using `ShellCompDirectiveFilterFileExt` Signed-off-by: Laura Brehm --- contrib/completion/bash/docker | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 71b41934b73e..1adfb9c823b9 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -1155,7 +1155,20 @@ __docker_complete_plugin() { resultArray+=( "$value" ) fi done - local result=$(eval "${resultArray[*]}" 2> /dev/null | grep -v '^:[0-9]*$') + local rawResult=$(eval "${resultArray[*]}" 2> /dev/null) + local result=$(grep -v '^:[0-9]*$' <<< "$rawResult") + + # Compose V2 completions sometimes returns returns `:8` (ShellCompDirectiveFilterFileExt) + # with the expected file extensions (such as `yml`, `yaml`) to indicate that the shell should + # provide autocompletions for files with matching extensions + local completionFlag=$(tail -1 <<< "$rawResult") + if [ "$completionFlag" == ":8" ]; then + # format a valid glob pattern for the provided file extensions + local filePattern=$(tr '\n' '|' <<< "$result") + + _filedir "$filePattern" + return + fi # if result empty, just use filename completion as fallback if [ -z "$result" ]; then