Merge pull request #4177 from thaJeztah/23.0_backport_fix_bash_file_completion

[23.0 backport] Fix plugin completion parsing for plugins using `ShellCompDirectiveFilterFileExt`
This commit is contained in:
Sebastiaan van Stijn 2023-04-11 09:29:11 +02:00 committed by GitHub
commit 726dfe92ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -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