diff --git a/gen-go-code.py b/gen-go-code.py index ce753c3e5..867d171f1 100755 --- a/gen-go-code.py +++ b/gen-go-code.py @@ -66,6 +66,11 @@ def generate_completions_for_kitty() -> None: print('k.Subcommand_must_be_first = true') for opt in go_options_for_seq(parse_option_spec()[0]): print(opt.as_completion_option('k')) + from kitty.config import option_names_for_completion + conf_names = ', '.join((f'"{serialize_as_go_string(x)}"' for x in option_names_for_completion())) + print(f'k.find_option("-o").Completion_for_arg = complete_kitty_override("Config directives", []string{{{conf_names}}})') + print('k.find_option("--listen-on").Completion_for_arg = complete_kitty_listen_on') + print('plus := k.add_command("+", "Entry point")') print('plus.Description = "Various special purpose tools and kittens"') diff --git a/kitty_tests/completion.py b/kitty_tests/completion.py index da720f535..170a9fadd 100644 --- a/kitty_tests/completion.py +++ b/kitty_tests/completion.py @@ -125,6 +125,9 @@ def completion(self: TestCompletion, tdir: str): add('kitty --directory ', all_words('bin/', 'sub/')) add('kitty -1d ', all_words('bin/', 'sub/')) add('kitty -1d', all_words('-1d')) + add('kitty -o a', has_words('allow_remote_control=')) + add('kitty --listen-on ', all_words('unix:', 'tcp:')) + add('kitty --listen-on unix:b', all_words('unix:bin/')) add('kitty --directory=', all_words('--directory=bin/', '--directory=sub/')) add('kitty --start-as=m', all_words('--start-as=minimized', '--start-as=maximized')) add('kitty @launch --ty', has_words('--type')) diff --git a/tools/completion/kitty.go b/tools/completion/kitty.go index c48d5afc5..d892bd5e1 100644 --- a/tools/completion/kitty.go +++ b/tools/completion/kitty.go @@ -48,6 +48,31 @@ func complete_kitty(completions *Completions, word string, arg_num int) { } } +func complete_kitty_override(title string, names []string) completion_func { + return func(completions *Completions, word string, arg_num int) { + mg := completions.add_match_group(title) + for _, q := range names { + if strings.HasPrefix(q, word) { + mg.add_match(q + "=") + } + } + } +} + +func complete_kitty_listen_on(completions *Completions, word string, arg_num int) { + if !strings.Contains(word, ":") { + mg := completions.add_match_group("Address family") + for _, q := range []string{"unix:", "tcp:"} { + if strings.HasPrefix(q, word) { + mg.add_match(q) + } + } + } else if strings.HasPrefix(word, "unix:") && !strings.HasPrefix(word, "unix:@") { + fnmatch_completer("UNIX sockets", CWD, "*")(completions, word[len("unix:"):], arg_num) + completions.add_prefix_to_all_matches("unix:") + } +} + func complete_plus_launch(completions *Completions, word string, arg_num int) { if arg_num == 1 { fnmatch_completer("Python scripts", CWD, "*.py")(completions, word, arg_num)