Skip to content

Commit

Permalink
Fix plugin completion parsing for plugins using `ShellCompDirectiveFi…
Browse files Browse the repository at this point in the history
…lterFileExt`

Signed-off-by: Laura Brehm <[email protected]>
  • Loading branch information
laurazard committed Apr 3, 2023
1 parent 88924b1 commit 683e4bf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 683e4bf

Please sign in to comment.