Skip to content

Commit 1d9491c

Browse files
authored
Merge pull request #4136 from laurazard/fix-bash-file-completion
Fix plugin completion results parsing for `ShellCompDirectiveFilterFileExt`
2 parents a5d4fb1 + 683e4bf commit 1d9491c

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

contrib/completion/bash/docker

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,20 @@ __docker_complete_plugin() {
11551155
resultArray+=( "$value" )
11561156
fi
11571157
done
1158-
local result=$(eval "${resultArray[*]}" 2> /dev/null | grep -v '^:[0-9]*$')
1158+
local rawResult=$(eval "${resultArray[*]}" 2> /dev/null)
1159+
local result=$(grep -v '^:[0-9]*$' <<< "$rawResult")
1160+
1161+
# Compose V2 completions sometimes returns returns `:8` (ShellCompDirectiveFilterFileExt)
1162+
# with the expected file extensions (such as `yml`, `yaml`) to indicate that the shell should
1163+
# provide autocompletions for files with matching extensions
1164+
local completionFlag=$(tail -1 <<< "$rawResult")
1165+
if [ "$completionFlag" == ":8" ]; then
1166+
# format a valid glob pattern for the provided file extensions
1167+
local filePattern=$(tr '\n' '|' <<< "$result")
1168+
1169+
_filedir "$filePattern"
1170+
return
1171+
fi
11591172

11601173
# if result empty, just use filename completion as fallback
11611174
if [ -z "$result" ]; then

0 commit comments

Comments
 (0)