mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-12 10:47:05 +02:00
More completion work
This commit is contained in:
@@ -250,3 +250,20 @@ func fnmatch_completer(title string, relative_to relative_to, patterns ...string
|
||||
func mimepat_completer(title string, relative_to relative_to, patterns ...string) completion_func {
|
||||
return make_completer(title, relative_to, patterns, complete_by_mimepat)
|
||||
}
|
||||
|
||||
func directory_completer(title string, relative_to relative_to) completion_func {
|
||||
if title == "" {
|
||||
title = "Directories"
|
||||
}
|
||||
cwd := get_cwd_for_completion(relative_to)
|
||||
|
||||
return func(completions *Completions, word string, arg_num int) {
|
||||
mg := completions.add_match_group(title)
|
||||
mg.IsFiles = true
|
||||
complete_files(word, func(entry *FileEntry) {
|
||||
if entry.mode.IsDir() {
|
||||
mg.add_match(entry.completion_candidate)
|
||||
}
|
||||
}, cwd)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ import (
|
||||
var _ = fmt.Print
|
||||
|
||||
func complete_kitty(completions *Completions, word string, arg_num int) {
|
||||
if arg_num > 1 {
|
||||
return
|
||||
}
|
||||
exes := complete_executables_in_path(word)
|
||||
if len(exes) > 0 {
|
||||
mg := completions.add_match_group("Executables in PATH")
|
||||
|
||||
@@ -100,7 +100,7 @@ func complete_word(word string, completions *Completions, only_args_allowed bool
|
||||
}
|
||||
return
|
||||
}
|
||||
if arg_num == 1 && cmd.has_subcommands() {
|
||||
if cmd.has_subcommands() && cmd.sub_command_allowed_at(completions, arg_num) {
|
||||
for _, cg := range cmd.Groups {
|
||||
group := completions.add_match_group(cg.Title)
|
||||
if group.Title == "" {
|
||||
@@ -163,7 +163,7 @@ func (cmd *Command) parse_args(words []string, completions *Completions) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
if cmd.has_subcommands() && arg_num == 1 {
|
||||
if cmd.has_subcommands() && cmd.sub_command_allowed_at(completions, arg_num) {
|
||||
sc := cmd.find_subcommand_with_name(word)
|
||||
if sc == nil {
|
||||
only_args_allowed = true
|
||||
|
||||
@@ -68,6 +68,7 @@ type Command struct {
|
||||
Completion_for_arg completion_func
|
||||
Stop_processing_at_arg int
|
||||
First_arg_may_not_be_subcommand bool
|
||||
Subcommand_must_be_first bool
|
||||
}
|
||||
|
||||
func (self *Command) add_group(name string) *CommandGroup {
|
||||
@@ -122,6 +123,13 @@ func (self *Command) has_subcommands() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *Command) sub_command_allowed_at(completions *Completions, arg_num int) bool {
|
||||
if self.Subcommand_must_be_first {
|
||||
return arg_num == 1 && completions.current_word_idx == 0
|
||||
}
|
||||
return arg_num == 1
|
||||
}
|
||||
|
||||
func (self *Command) add_option(opt *Option) {
|
||||
self.Options = append(self.Options, opt)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user