Clean up previous PR

This commit is contained in:
Kovid Goyal 2023-02-03 16:14:24 +05:30
parent 9adc474e3c
commit f1dc072045
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 13 additions and 17 deletions

View File

@ -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) {

View File

@ -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
}

View File

@ -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) {

View File

@ -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) {