Skip to content

Commit 115cacd

Browse files
Improve support for multi-word completion strings in ZSH (#216)
* Improve support for multi-word completions in Z shell I will not pretend to fully understand why this new "expand string into array" expression works when the other didn't, but it does. The new expression is based on this SO answer: https://unix.stackexchange.com/a/29748. The motivation for this change was for the install command of xcodes (https://github.com/RobotsAndPencils/xcodes) to support Xcode version completion strings with multiple words, like "11.6 Beta". The previous version of this expression would split this string into two, so that "11.6" and "Beta" were independent options in the ZSH completion UI, which didn't make sense for this use case.
1 parent c3c1a5f commit 115cacd

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct ZshCompletionsGenerator {
2222
2323
\(generateCompletionFunction([type]))
2424
_custom_completion() {
25-
local completions=($($*))
25+
local completions=("${(@f)$($*)}")
2626
_describe '' completions
2727
}
2828

Tests/ArgumentParserExampleTests/MathExampleTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ _math_help() {
495495
496496
497497
_custom_completion() {
498-
local completions=($($*))
498+
local completions=("${(@f)$($*)}")
499499
_describe '' completions
500500
}
501501

Tests/ArgumentParserUnitTests/CompletionScriptTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ _base() {
154154
155155
156156
_custom_completion() {
157-
local completions=($($*))
157+
local completions=("${(@f)$($*)}")
158158
_describe '' completions
159159
}
160160
@@ -226,7 +226,7 @@ _escaped() {
226226
227227
228228
_custom_completion() {
229-
local completions=($($*))
229+
local completions=("${(@f)$($*)}")
230230
_describe '' completions
231231
}
232232

0 commit comments

Comments
 (0)