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 var _ = fmt.Print
func bash_completion_script(commands []string) ([]byte, error) { func bash_completion_script(commands []string) (string, error) {
script := `_ksi_completions() { return `_ksi_completions() {
builtin local src builtin local src
builtin local limit builtin local limit
# Send all words up to the word the cursor is currently on # 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 edit-in-kitty
builtin complete -F _ksi_completions clone-in-kitty builtin complete -F _ksi_completions clone-in-kitty
builtin complete -F _ksi_completions kitten builtin complete -F _ksi_completions kitten
` `, nil
return []byte(script), nil
} }
func bash_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) { 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) 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 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) 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 output_type == "setup" {
if len(args) == 0 { 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] shell_name := args[0]
args = args[1:] args = args[1:]
@ -75,7 +75,7 @@ func GenerateCompletions(args []string) error {
} }
output, err := completion_script(args) output, err := completion_script(args)
if err == nil { if err == nil {
_, err = os.Stdout.Write(output) _, err = os.Stdout.WriteString(output)
} }
return err return err
} }

View File

@ -12,7 +12,7 @@ import (
var _ = fmt.Print 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. // One command in fish requires one completion script.
// Usage: kitten __complete__ setup fish [kitty|kitten|clone-in-kitty] // Usage: kitten __complete__ setup fish [kitty|kitten|clone-in-kitty]
all_commands := map[string]bool{ all_commands := map[string]bool{
@ -21,9 +21,7 @@ func fish_completion_script(commands []string) ([]byte, error) {
"kitten": true, "kitten": true,
} }
if len(commands) == 0 { if len(commands) == 0 {
for cmd, _ := range all_commands { commands = append(commands, utils.Keys(all_commands)...)
commands = append(commands, cmd)
}
} }
script := strings.Builder{} script := strings.Builder{}
script.WriteString(`function __ksi_completions script.WriteString(`function __ksi_completions
@ -40,10 +38,10 @@ end
// Reserved for `setup SHELL [KEY=VALUE ...]`, not used now. // Reserved for `setup SHELL [KEY=VALUE ...]`, not used now.
continue continue
} else { } 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) { func fish_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) {

View File

@ -15,8 +15,8 @@ import (
var _ = fmt.Print var _ = fmt.Print
func zsh_completion_script(commands []string) ([]byte, error) { func zsh_completion_script(commands []string) (string, error) {
script := `#compdef kitty return `#compdef kitty
_kitty() { _kitty() {
(( ${+commands[kitten]} )) || builtin return (( ${+commands[kitten]} )) || builtin return
@ -31,8 +31,7 @@ if (( $+functions[compdef] )); then
compdef _kitty clone-in-kitty compdef _kitty clone-in-kitty
compdef _kitty kitten compdef _kitty kitten
fi fi
` `, nil
return []byte(script), nil
} }
func shell_input_parser(data []byte, shell_state map[string]string) ([][]string, error) { func shell_input_parser(data []byte, shell_state map[string]string) ([][]string, error) {