diff --git a/tools/cli/files.go b/tools/cli/files.go index 963c2b31c..2e0fdc18b 100644 --- a/tools/cli/files.go +++ b/tools/cli/files.go @@ -4,7 +4,6 @@ package cli import ( "fmt" - "mime" "os" "path/filepath" "slices" @@ -191,16 +190,7 @@ func complete_by_mimepat(prefix, cwd string, patterns []string) []string { if all_allowed { return true } - idx := strings.Index(name, ".") - if idx < 1 { - return false - } - ext := name[idx:] - mt := mime.TypeByExtension(ext) - if mt == "" { - ext = filepath.Ext(name) - mt = mime.TypeByExtension(ext) - } + mt := utils.GuessMimeType(name) if mt == "" { return false } diff --git a/tools/cli/files_test.go b/tools/cli/files_test.go index 486b9a19e..44e5dbf82 100644 --- a/tools/cli/files_test.go +++ b/tools/cli/files_test.go @@ -124,6 +124,20 @@ func TestCompleteFiles(t *testing.T) { if !found { t.Fatalf("Directory containing only an uppercase extension match not completed by FnmatchCompleter: %#v", c.Groups) } + + // mime types kitty knows about but the Go stdlib does not + create("zz.py") + c = NewCompletions() + MimepatCompleter("", CWD, "text/*")(c, "zz", 0) + found = false + for _, g := range c.Groups { + for _, m := range g.Matches { + found = found || m.Word == "zz.py" + } + } + if !found { + t.Fatalf("File with a mime type known only to kitty not completed by MimepatCompleter: %#v", c.Groups) + } } func TestCompleteExecutables(t *testing.T) {