Add various special purpose entry points
This commit is contained in:
parent
3bf20594b7
commit
c2a2b4c087
@ -66,6 +66,22 @@ 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'))
|
||||
print('plus := k.add_command("+", "Entry point")')
|
||||
print('plus.Description = "Various special purpose tools and kittens"')
|
||||
|
||||
print('plus_launch := plus.add_command("launch", "Launch Python script")')
|
||||
print('plus_launch.Completion_for_arg = complete_plus_launch')
|
||||
print('k.add_clone("+launch", "Launch Python scripts", plus_launch)')
|
||||
|
||||
print('plus_runpy := plus.add_command("runpy", "Run python code")')
|
||||
print('plus_runpy.Completion_for_arg = complete_plus_runpy')
|
||||
print('k.add_clone("+runpy", "Run Python code", plus_runpy)')
|
||||
|
||||
print('plus_open := plus.add_command("open", "Open files and URLs")')
|
||||
print('plus_open.Completion_for_arg = complete_plus_open')
|
||||
print('plus_open.clone_options_from(k)')
|
||||
print('k.add_clone("+open", "Open files and URLs", plus_open)')
|
||||
|
||||
print('at := k.add_command("@", "Remote control")')
|
||||
print('at.Description = "Control kitty using commands"')
|
||||
for go_name in all_command_names():
|
||||
|
||||
@ -79,7 +79,7 @@ def completion(self: TestCompletion, tdir: str):
|
||||
self.assertEqual(cp.returncode, 0, f'kitty-tool __complete__ failed with exit code: {cp.returncode}')
|
||||
return json.loads(cp.stdout)
|
||||
|
||||
add('kitty ', has_words('@', '@ls'))
|
||||
add('kitty ', has_words('@', '@ls', '+', '+open'))
|
||||
add('kitty @ l', has_words('ls', 'last-used-layout', 'launch'))
|
||||
add('kitty @l', has_words('@ls', '@last-used-layout', '@launch'))
|
||||
|
||||
@ -112,6 +112,8 @@ def completion(self: TestCompletion, tdir: str):
|
||||
add('kitty @ set-window-logo ', all_words('exe-not2.jpeg', 'sub/'))
|
||||
add('kitty @ set-window-logo e', all_words('exe-not2.jpeg'))
|
||||
add('kitty @ set-window-logo e e', all_words())
|
||||
add('kitty +ope', has_words('+open'))
|
||||
add('kitty +open -', has_words('-1', '-T'))
|
||||
|
||||
add('kitty -', has_words('-c', '-1', '--'), does_not_have_words('--config', '--single-instance'))
|
||||
add('kitty -c', all_words('-c'))
|
||||
|
||||
@ -47,3 +47,28 @@ func complete_kitty(completions *Completions, word string, arg_num int) {
|
||||
}, "")
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
if strings.HasPrefix(word, ":") {
|
||||
exes := complete_executables_in_path(word[1:])
|
||||
mg := completions.add_match_group("Python scripts in PATH")
|
||||
for _, exe := range exes {
|
||||
mg.add_match(":" + exe)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fnmatch_completer("Files", CWD, "*")(completions, word, arg_num)
|
||||
}
|
||||
}
|
||||
|
||||
func complete_plus_runpy(completions *Completions, word string, arg_num int) {
|
||||
if arg_num > 1 {
|
||||
fnmatch_completer("Files", CWD, "*")(completions, word, arg_num)
|
||||
}
|
||||
}
|
||||
|
||||
func complete_plus_open(completions *Completions, word string, arg_num int) {
|
||||
fnmatch_completer("Files", CWD, "*")(completions, word, arg_num)
|
||||
}
|
||||
|
||||
@ -22,6 +22,12 @@ func (self *MatchGroup) add_match(word string, description ...string) *Match {
|
||||
return &ans
|
||||
}
|
||||
|
||||
func (self *MatchGroup) add_prefix_to_all_matches(prefix string) {
|
||||
for _, m := range self.Matches {
|
||||
m.Word = prefix + m.Word
|
||||
}
|
||||
}
|
||||
|
||||
type Completions struct {
|
||||
Groups []*MatchGroup `json:"groups,omitempty"`
|
||||
|
||||
@ -32,9 +38,7 @@ type Completions struct {
|
||||
|
||||
func (self *Completions) add_prefix_to_all_matches(prefix string) {
|
||||
for _, mg := range self.Groups {
|
||||
for _, m := range mg.Matches {
|
||||
m.Word = prefix + m.Word
|
||||
}
|
||||
mg.add_prefix_to_all_matches(prefix)
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,6 +81,12 @@ type Command struct {
|
||||
Subcommand_must_be_first bool
|
||||
}
|
||||
|
||||
func (self *Command) clone_options_from(other *Command) {
|
||||
for _, opt := range other.Options {
|
||||
self.Options = append(self.Options, opt)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Command) add_group(name string) *CommandGroup {
|
||||
for _, g := range self.Groups {
|
||||
if g.Title == name {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user