From 6125c26acabd93689754c02efe45b246093f910c Mon Sep 17 00:00:00 2001 From: David Gamba Date: Tue, 7 Nov 2023 22:53:18 -0700 Subject: [PATCH] completions: only insert space after single completion result for bash --- api.go | 2 +- user_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index a1a51e6..7631138 100644 --- a/api.go +++ b/api.go @@ -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 diff --git a/user_test.go b/user_test.go index a474314..1374ec7 100644 --- a/user_test.go +++ b/user_test.go @@ -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", ""}, @@ -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 {