diff --git a/tools/cli/bash.go b/tools/cli/bash.go index f01c896d8..c438ff783 100644 --- a/tools/cli/bash.go +++ b/tools/cli/bash.go @@ -11,8 +11,8 @@ import ( var _ = fmt.Print -func bash_completion_script(commands []string) ([]byte, error) { - script := `_ksi_completions() { +func bash_completion_script(commands []string) (string, error) { + return `_ksi_completions() { builtin local src builtin local limit # Send all words up to the word the cursor is currently on @@ -27,8 +27,7 @@ builtin complete -F _ksi_completions kitty builtin complete -F _ksi_completions edit-in-kitty builtin complete -F _ksi_completions clone-in-kitty builtin complete -F _ksi_completions kitten -` - return []byte(script), nil +`, nil } func bash_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) { diff --git a/tools/cli/completion-main.go b/tools/cli/completion-main.go index 6840974ad..55821fd1f 100644 --- a/tools/cli/completion-main.go +++ b/tools/cli/completion-main.go @@ -30,7 +30,7 @@ func json_output_serializer(completions []*Completions, shell_state map[string]s return json.Marshal(completions) } -type completion_script_func func(commands []string) ([]byte, error) +type completion_script_func func(commands []string) (string, error) type parser_func func(data []byte, shell_state map[string]string) ([][]string, error) type serializer_func func(completions []*Completions, shell_state map[string]string) ([]byte, error) @@ -65,7 +65,7 @@ func GenerateCompletions(args []string) error { } if output_type == "setup" { if len(args) == 0 { - return fmt.Errorf("The shell needs to be specified") + return fmt.Errorf("The shell must be specified") } shell_name := args[0] args = args[1:] @@ -75,7 +75,7 @@ func GenerateCompletions(args []string) error { } output, err := completion_script(args) if err == nil { - _, err = os.Stdout.Write(output) + _, err = os.Stdout.WriteString(output) } return err } diff --git a/tools/cli/fish.go b/tools/cli/fish.go index ea139de69..c9068fcb8 100644 --- a/tools/cli/fish.go +++ b/tools/cli/fish.go @@ -12,7 +12,7 @@ import ( var _ = fmt.Print -func fish_completion_script(commands []string) ([]byte, error) { +func fish_completion_script(commands []string) (string, error) { // One command in fish requires one completion script. // Usage: kitten __complete__ setup fish [kitty|kitten|clone-in-kitty] all_commands := map[string]bool{ @@ -21,9 +21,7 @@ func fish_completion_script(commands []string) ([]byte, error) { "kitten": true, } if len(commands) == 0 { - for cmd, _ := range all_commands { - commands = append(commands, cmd) - } + commands = append(commands, utils.Keys(all_commands)...) } script := strings.Builder{} script.WriteString(`function __ksi_completions @@ -40,10 +38,10 @@ end // Reserved for `setup SHELL [KEY=VALUE ...]`, not used now. continue } else { - return nil, fmt.Errorf("No fish completion script for command: %s", cmd) + return "", fmt.Errorf("No fish completion script for command: %s", cmd) } } - return []byte(script.String()), nil + return script.String(), nil } func fish_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) { diff --git a/tools/cli/zsh.go b/tools/cli/zsh.go index bf12de3cb..f810062fe 100644 --- a/tools/cli/zsh.go +++ b/tools/cli/zsh.go @@ -15,8 +15,8 @@ import ( var _ = fmt.Print -func zsh_completion_script(commands []string) ([]byte, error) { - script := `#compdef kitty +func zsh_completion_script(commands []string) (string, error) { + return `#compdef kitty _kitty() { (( ${+commands[kitten]} )) || builtin return @@ -31,8 +31,7 @@ if (( $+functions[compdef] )); then compdef _kitty clone-in-kitty compdef _kitty kitten fi -` - return []byte(script), nil +`, nil } func shell_input_parser(data []byte, shell_state map[string]string) ([][]string, error) {