Extra completion for some kitty options

This commit is contained in:
Kovid Goyal 2022-09-16 21:55:31 +05:30
parent c2a2b4c087
commit 25a7ec9a07
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 33 additions and 0 deletions

View File

@ -66,6 +66,11 @@ def generate_completions_for_kitty() -> None:
print('k.Subcommand_must_be_first = true') print('k.Subcommand_must_be_first = true')
for opt in go_options_for_seq(parse_option_spec()[0]): for opt in go_options_for_seq(parse_option_spec()[0]):
print(opt.as_completion_option('k')) 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 := k.add_command("+", "Entry point")')
print('plus.Description = "Various special purpose tools and kittens"') print('plus.Description = "Various special purpose tools and kittens"')

View File

@ -125,6 +125,9 @@ def completion(self: TestCompletion, tdir: str):
add('kitty --directory ', all_words('bin/', 'sub/')) add('kitty --directory ', all_words('bin/', 'sub/'))
add('kitty -1d ', all_words('bin/', 'sub/')) add('kitty -1d ', all_words('bin/', 'sub/'))
add('kitty -1d', all_words('-1d')) 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 --directory=', all_words('--directory=bin/', '--directory=sub/'))
add('kitty --start-as=m', all_words('--start-as=minimized', '--start-as=maximized')) add('kitty --start-as=m', all_words('--start-as=minimized', '--start-as=maximized'))
add('kitty @launch --ty', has_words('--type')) add('kitty @launch --ty', has_words('--type'))

View File

@ -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) { func complete_plus_launch(completions *Completions, word string, arg_num int) {
if arg_num == 1 { if arg_num == 1 {
fnmatch_completer("Python scripts", CWD, "*.py")(completions, word, arg_num) fnmatch_completer("Python scripts", CWD, "*.py")(completions, word, arg_num)