From 579c7350143060f5efaf47b5879d2c6fcd56d792 Mon Sep 17 00:00:00 2001 From: devangpratap <115096812+devangpratap@users.noreply.github.com> Date: Wed, 16 Sep 2026 05:43:17 -0400 Subject: [PATCH] Use GuessMimeType for mime based completion complete_by_mimepat called mime.TypeByExtension directly, so it saw only the extensions the Go standard library knows about. Everything else in kitty that needs a mime type goes through utils.GuessMimeType, which also consults the user's mime.types, kitty's builtin types and KnownExtensions. As a result files like foo.py or foo.toml were not offered when completing arguments that ask for text/*, even though kitten pager opens them as text. --- tools/cli/files.go | 12 +----------- tools/cli/files_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) 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) {