Skip to content

Commit

Permalink
completions: only insert space after single completion result for bash
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGamba committed Nov 8, 2023
1 parent 00d9a78 commit 6125c26
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ ARGS_LOOP:
sort.Strings(completions)
// Add trailing space to force next completion, makes for nicer UI when there is a single result.
// In most cases this is not required but sometimes the compspec just seems to get stuck.
if len(completions) == 1 {
if len(completions) == 1 && completionMode == "bash" {
(completions)[0] = completions[0] + " "
}
return currentProgramNode, completions, nil
Expand Down
4 changes: 2 additions & 2 deletions user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ ERROR: wrong value for option 'profile', valid values are ["dev" "staging" "prod
{"zshell option", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program --f") }, []string{}, "--f\n--flag\n--fleg\n", ""},
{"zshell option", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program --fl") }, []string{}, "--flag\n--fleg\n", ""},
{"zshell option", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program --d") }, []string{}, "--debug\n", ""},
{"zshell command", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program h") }, []string{}, "help \n", ""},
{"zshell command", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program h") }, []string{}, "help\n", ""},
{"zshell command", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program help ") }, []string{}, "log\nshow\n", ""},
// TODO: --profile= when there are suggestions is probably not wanted
{"zshell command", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program --profile") }, []string{}, "--profile=\n--profile=dev\n--profile=production\n--profile=staging\n", ""},
Expand All @@ -229,7 +229,7 @@ ERROR: wrong value for option 'profile', valid values are ["dev" "staging" "prod
{"zshell command", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program --profile=a ") }, []string{}, "", `
ERROR: wrong value for option 'profile', valid values are ["dev" "staging" "production"]
`},
{"zshell command", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program lo ") }, []string{"./program", "lo", "./program"}, "log \n", ""},
{"zshell command", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program lo ") }, []string{"./program", "lo", "./program"}, "log\n", ""},
{"zshell command", func() { os.Setenv("ZSHELL", "true"); os.Setenv("COMP_LINE", "./program show sub-show ") }, []string{}, "hello\nhelp\npassword\nprofile\n", ""},
}
for _, tt := range tests {
Expand Down

0 comments on commit 6125c26

Please sign in to comment.