//! Filetypes for the Duat text editor
//!
//! This [`Plugin`] is included by default, as it is considered a core
//! utility of duat. It adds the two following traits:
//!
//! - [`FileType`]: This trait grants the [`filetype`] method, which
//!   lets you access the filetype directly. Its implementors are the
//!   [`Buffer`] widget, [`String`] and [`&str`] and [`PathBuf`] and
//!   [`Path`].
//! - [`PassFileType`]: This trait also has a
//!   [`filetype`](PassFileType::filetype) method, but it requires a
//!   [`Pass`], bypassing the need to, for example, [`read`] a
//!   [`Handle<Buffer>`]. Its implementors are [`RwData<Buffer>`],
//!   [`Handle<Buffer>`].
//!
//! [`Plugin`]: duat_core::Plugin
//! [`filetype`]: FileType::filetype
//! [`Buffer`]: duat_core::buffer::Buffer
//! [`&str`]: str
//! [`Pass`]: duat_core::data::Pass
//! [`read`]: duat_core::context::Handle::read
//! [`Handle<Buffer>`]: duat_core::context::Handle
//! [`RwData<Buffer>`]: duat_core::data::RwData
//! [hook]: duat_core::hook
//! [`prelude`]: https://docs.rs/duat/latest/duat/prelude
pub use prefixes::AutoPrefix;
use std::{
    collections::HashMap,
    path::{Path, PathBuf},
    sync::LazyLock,
};

use duat_core::{
    buffer::Buffer,
    context::Handle,
    data::{Pass, RwData},
    mode::Cursor,
};
use regex::RegexSet;

mod prefixes;

pub trait FileType {
    fn filetype(&self) -> Option<&'static str>;
}

impl FileType for Buffer {
    fn filetype(&self) -> Option<&'static str> {
        PathBuf::from(self.path_set()?).filetype()
    }
}

impl FileType for Cursor<'_> {
    fn filetype(&self) -> Option<&'static str> {
        self.widget().filetype()
    }
}

impl FileType for String {
    fn filetype(&self) -> Option<&'static str> {
        AsRef::<str>::as_ref(&self).filetype()
    }
}

impl FileType for &'_ str {
    fn filetype(&self) -> Option<&'static str> {
        Path::new(self).filetype()
    }
}

impl FileType for PathBuf {
    fn filetype(&self) -> Option<&'static str> {
        self.as_path().filetype()
    }
}

impl FileType for &'_ Path {
    fn filetype(&self) -> Option<&'static str> {
        self.extension()
            .and_then(|ext| EXTENSIONS.get(ext.to_str()?).copied())
            .or_else(|| FILENAMES.get(self.to_str()?).copied())
            .or_else(|| FILENAMES.get(self.file_name()?.to_str()?).copied())
            .or_else(|| {
                let (patterns, langs) = &*PATTERNS;

                langs
                    .get(patterns.matches(self.to_str()?).iter().min()?)
                    .copied()
            })
    }
}

pub trait PassFileType {
    fn filetype(&self, pa: &Pass) -> Option<&'static str>;
}

impl PassFileType for RwData<Buffer> {
    fn filetype(&self, pa: &Pass) -> Option<&'static str> {
        self.read(pa).filetype()
    }
}

impl PassFileType for Handle<Buffer> {
    fn filetype(&self, pa: &Pass) -> Option<&'static str> {
        self.read(pa).filetype()
    }
}

macro_rules! fmt{
    ($($tt:tt)*) => {{
        let str: &'static str = format!($($tt)*).leak();
        str
    }}
}

static EXTENSIONS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
    HashMap::from_iter([
        ("8th", "8th"),
        ("a65", "a65"),
        ("aap", "aap"),
        ("abap", "abap"),
        ("abc", "abc"),
        ("abl", "abel"),
        ("abnf", "abnf"),
        ("wrm", "acedb"),
        ("ads", "ada"),
        ("ada", "ada"),
        ("gpr", "ada"),
        ("adb", "ada"),
        ("tdf", "ahdl"),
        ("aidl", "aidl"),
        ("aml", "aml"),
        ("run", "ampl"),
        ("g4", "antlr4"),
        ("scpt", "applescript"),
        ("ino", "arduino"),
        ("pde", "arduino"),
        ("art", "art"),
        ("asciidoc", "asciidoc"),
        ("adoc", "asciidoc"),
        ("asa", "aspvbs"),
        // TODO: implement detection of other asm syntax
        ("asm", "asm"),
        ("s", "asm"),
        ("S", "asm"),
        ("a", "asm"),
        ("A", "asm"),
        ("lst", "asm"),
        ("mac", "asm"),
        ("asn1", "asn"),
        ("asn", "asn"),
        // TODO: implement detection of Active Server Pages
        ("asp", "aspvbs"),
        ("astro", "astro"),
        ("asy", "asy"),
        ("atl", "atlas"),
        ("as", "atlas"),
        ("zed", "authzed"),
        ("ahk", "autohotkey"),
        ("au3", "autoit"),
        ("ave", "ave"),
        ("gawk", "awk"),
        ("awk", "awk"),
        ("ref", "b"),
        ("imp", "b"),
        ("mch", "b"),
        // TODO: implement detection of basic (for WHOM???)
        ("bas", "basic"),
        ("bass", "bass"),
        ("bi", "basic"),
        ("bm", "basic"),
        ("bc", "bc"),
        ("bdf", "bdf"),
        ("beancount", "beancount"),
        ("bib", "bib"),
        // TODO: bindzone detection or wtv
        ("com", "dcl"),
        ("db", "bindzone"),
        ("bicep", "bicep"),
        ("bicepparam", "bicep"),
        ("zone", "bindzone"),
        ("bb", "bitbake"),
        ("bbappend", "bitbake"),
        ("bbclass", "bitbake"),
        ("bl", "blank"),
        ("blp", "blueprint"),
        ("bp", "bp"),
        ("bsd", "bsdl"),
        ("bsdl", "bsdl"),
        ("bst", "bst"),
        // TODO: dosbatch detection
        ("btm", "btm"),
        ("bzl", "bzl"),
        ("bazel", "bzl"),
        ("BUILD", "bzl"),
        ("mdh", "c"),
        ("epro", "c"),
        ("qc", "c"),
        ("c3", "c3"),
        ("c3i", "c3"),
        ("c3t", "c3"),
        ("cabal", "cabal"),
        ("cairo", "cairo"),
        ("capnp", "capnp"),
        ("cdc", "cdc"),
        ("cdl", "cdl"),
        // TODO: Biased for tex, ngl
        ("toc", "tex"),
        ("cedar", "cedar"),
        ("cfc", "cf"),
        ("cfm", "cf"),
        ("cfi", "cf"),
        ("hgrc", "cfg"),
        // TODO: Other meanings for cfg, i guess
        ("cfg", "cfg"),
        ("Cfg", "cfg"),
        ("CFG", "cfg"),
        ("chf", "ch"),
        ("chai", "chaiscript"),
        // TODO: change, ch, et. all
        ("ch", "chill"),
        ("chs", "chaskell"),
        ("chatito", "chatito"),
        ("chopro", "chordpro"),
        ("crd", "chordpro"),
        ("crdpro", "chordpro"),
        ("cho", "chordpro"),
        ("chordpro", "chordpro"),
        ("ck", "chuck"),
        // TODO: detect opencl
        ("cl", "lisp"),
        ("eni", "cl"),
        ("icl", "clean"),
        ("cljx", "clojure"),
        ("clj", "clojure"),
        ("cljc", "clojure"),
        ("cljs", "clojure"),
        ("cook", "cook"),
        ("cmake", "cmake"),
        ("cmod", "cmod"),
        ("cob", "cobol"),
        ("cbl", "cobol"),
        ("atg", "coco"),
        ("recipe", "conaryrecipe"),
        ("ctags", "conf"),
        // TODO: nil-ing, i guess?
        ("hook", "confini"),
        ("nmconnection", "confini"),
        ("mklx", "context"),
        ("mkiv", "context"),
        ("mkii", "context"),
        ("mkxl", "context"),
        ("mkvi", "context"),
        // TODO: nil-ing, i guess?
        ("control", "debcontrol"),
        // TODO: nil-ing, i guess?
        ("copyright", "debcopyright"),
        ("corn", "corn"),
        // TODO: other types of csh
        ("csh", "csh"),
        ("cpon", "cpon"),
        ("moc", "cpp"),
        ("hh", "cpp"),
        ("tlh", "cpp"),
        ("inl", "cpp"),
        ("ipp", "cpp"),
        ("c++", "cpp"),
        ("C", "cpp"),
        ("cxx", "cpp"),
        ("H", "cpp"),
        ("tcc", "cpp"),
        ("hxx", "cpp"),
        ("hpp", "cpp"),
        ("ixx", "cpp"),
        ("mpp", "cpp"),
        ("ccm", "cpp"),
        ("cppm", "cpp"),
        ("cxxm", "cpp"),
        ("c++m", "cpp"),
        // TODO: Whatever the hell is cynlib
        ("cpp", "cpp"),
        ("cc", "cpp"),
        ("cql", "cqlang"),
        ("crm", "crm"),
        ("cr", "crystal"),
        ("cake", "cs"),
        ("csx", "cs"),
        ("cs", "cs"),
        ("csc", "csc"),
        ("csdl", "csdl"),
        ("cshtml", "html"),
        ("fdr", "csp"),
        ("csp", "csp"),
        ("css", "css"),
        ("csv", "csv"),
        ("con", "cterm"),
        ("feature", "cucumber"),
        ("cuh", "cuda"),
        ("cu", "cuda"),
        ("cue", "cue"),
        ("pld", "cupl"),
        ("si", "cuplsim"),
        ("cyn", "cynpp"),
        ("cypher", "cypher"),
        ("dfy", "dafny"),
        ("dart", "dart"),
        ("drt", "dart"),
        ("ds", "datascript"),
        // TODO: Idek what the main one is tbh
        ("dat", "upstreamdat"),
        ("Dat", "upstreamdat"),
        ("DAT", "upstreamdat"),
        ("dax", "dax"),
        ("dcd", "dcd"),
        // TODO: nil-ing i guess?
        ("decl", "sgmldecl"),
        ("dec", "sgmldecl"),
        // TODO: Possibly decl
        ("dcl", "clean"),
        // TODO: Could be tex
        ("def", "def"),
        ("desc", "desc"),
        ("directory", "desktop"),
        ("desktop", "desktop"),
        ("dhall", "dhall"),
        ("diff", "diff"),
        ("rej", "diff"),
        ("Dockerfile", "dockerfile"),
        ("dockerfile", "dockerfile"),
        ("bat", "dosbatch"),
        ("wrap", "dosini"),
        ("ini", "dosini"),
        ("INI", "dosini"),
        ("vbp", "dosini"),
        ("dot", "dot"),
        ("gv", "dot"),
        ("drac", "dracula"),
        ("drc", "dracula"),
        ("lvs", "dracula"),
        ("lpe", "dracula"),
        // TODO: Could be faust
        ("dsp", "make"),
        ("dtd", "dtd"),
        // TODO: Could be dtrace
        ("d", "d"),
        ("dts", "dts"),
        ("dtsi", "dts"),
        ("dtso", "dts"),
        ("its", "dts"),
        ("keymap", "dts"),
        ("overlay", "dts"),
        ("dylan", "dylan"),
        ("intr", "dylanintr"),
        ("lid", "dylanlid"),
        // TODO: could be specman
        ("e", "eiffel"),
        ("E", "eiffel"),
        ("ecd", "ecd"),
        ("edf", "edif"),
        ("edif", "edif"),
        ("edo", "edif"),
        // TODO: could be edif
        ("edn", "closure"),
        ("eex", "eelixir"),
        ("leex", "eelixir"),
        ("am", "elf"),
        ("exs", "elixir"),
        ("elm", "elm"),
        ("lc", "elsa"),
        ("elv", "elvish"),
        // TODO: could be cl
        ("ent", "dtd"),
        ("epp", "epuppet"),
        ("erl", "erlang"),
        ("hrl", "erlang"),
        ("yaws", "erlang"),
        ("erb", "eruby"),
        ("rhtml", "eruby"),
        ("esdl", "esdl"),
        ("ec", "esqlc"),
        ("EC", "esqlc"),
        ("strl", "esterel"),
        // TODO: detect other euphorias
        ("eu", "euphoria3"),
        ("EU", "euphoria3"),
        ("ew", "euphoria3"),
        ("EW", "euphoria3"),
        ("EX", "euphoria3"),
        ("exu", "euphoria3"),
        ("EXU", "euphoria3"),
        ("exw", "euphoria3"),
        ("EXW", "euphoria3"),
        // TODO: could be euphoria
        ("ex", "elixir"),
        ("exp", "expect"),
        // TODO: could be forth
        ("f", "fortran"),
        ("factor", "factor"),
        ("fal", "falcon"),
        ("fan", "fan"),
        ("fwt", "fan"),
        ("lib", "faust"),
        ("fnl", "fennel"),
        ("m4gl", "fgl"),
        ("4gl", "fgl"),
        ("4gh", "fgl"),
        ("fir", "firrtl"),
        ("fish", "fish"),
        ("focexec", "focexec"),
        ("fex", "focexec"),
        ("ft", "forth"),
        ("fth", "forth"),
        ("4th", "forth"),
        ("FOR", "fortran"),
        ("f77", "fortran"),
        ("f03", "fortran"),
        ("fortran", "fortran"),
        ("F95", "fortran"),
        ("f90", "fortran"),
        ("F03", "fortran"),
        ("fpp", "fortran"),
        ("FTN", "fortran"),
        ("ftn", "fortran"),
        ("for", "fortran"),
        ("F90", "fortran"),
        ("F77", "fortran"),
        ("f95", "fortran"),
        ("FPP", "fortran"),
        ("F", "fortran"),
        ("F08", "fortran"),
        ("f08", "fortran"),
        ("fpc", "fpcmake"),
        ("fsl", "framescript"),
        // TODO: could be vb
        ("frm", "form"),
        ("fb", "freebasic"),
        ("fs", "fortran"),
        ("fsh", "fsh"),
        ("fsi", "fsharp"),
        ("fsx", "fsharp"),
        ("fc", "func"),
        ("fusion", "fusion"),
        ("gdb", "gdb"),
        ("gdmo", "gdmo"),
        ("mo", "gdmo"),
        ("tscn", "gdresource"),
        ("tres", "gdresource"),
        ("gd", "gdscript"),
        ("gdshader", "gdshader"),
        ("shader", "gdshader"),
        ("ged", "gedcom"),
        ("gel", "gel"),
        ("gmi", "gemtext"),
        ("gemini", "gemtext"),
        ("gift", "gift"),
        ("prettierignore", "gitignore"),
        ("gleam", "gleam"),
        ("vert", "glsl"),
        ("tesc", "glsl"),
        ("tese", "glsl"),
        ("glsl", "glsl"),
        ("geom", "glsl"),
        ("frag", "glsl"),
        ("comp", "glsl"),
        ("rgen", "glsl"),
        ("rmiss", "glsl"),
        ("rchit", "glsl"),
        ("rahit", "glsl"),
        ("rint", "glsl"),
        ("rcall", "glsl"),
        ("gn", "gn"),
        ("gni", "gn"),
        ("gnuplot", "gnuplot"),
        ("gpi", "gnuplot"),
        ("go", "go"),
        ("gp", "gp"),
        ("gs", "grads"),
        ("gql", "graphql"),
        ("graphql", "graphql"),
        ("graphqls", "graphql"),
        ("gretl", "gretl"),
        ("gradle", "groovy"),
        ("groovy", "groovy"),
        ("gsp", "gsp"),
        ("gjs", "javascript.glimmer"),
        ("gts", "typescript.glimmer"),
        ("gyp", "gyp"),
        ("gypi", "gyp"),
        ("hack", "hack"),
        ("hackpartial", "hack"),
        ("haml", "haml"),
        ("hsm", "hamster"),
        ("hbs", "handlebars"),
        ("ha", "hare"),
        ("hs-boot", "haskell"),
        ("hsig", "haskell"),
        ("hsc", "haskell"),
        ("hs", "haskell"),
        ("persistentmodels", "haskellpersistent"),
        ("ht", "haste"),
        ("htpp", "hastepreproc"),
        ("hcl", "hcl"),
        ("hb", "hb"),
        // TODO: could be various other c clones
        ("h", "c"),
        ("sum", "hercules"),
        ("errsum", "hercules"),
        ("ev", "hercules"),
        ("vc", "hercules"),
        ("heex", "heex"),
        ("hex", "hex"),
        ("a43", "hex"),
        ("a90", "hex"),
        ("h32", "hex"),
        ("h80", "hex"),
        ("h86", "hex"),
        ("ihex", "hex"),
        ("ihe", "hex"),
        ("ihx", "hex"),
        ("int", "hex"),
        ("mcs", "hex"),
        ("hjson", "hjson"),
        ("m3u", "hlsplaylist"),
        ("m3u8", "hlsplaylist"),
        ("hog", "hog"),
        ("hws", "hollywood"),
        ("hoon", "hoon"),
        // TODO: could be other flavors of html
        ("cpt", "html"),
        ("dtml", "html"),
        ("htm", "html"),
        ("html", "html"),
        ("pt", "html"),
        ("shtml", "html"),
        ("stm", "html"),
        ("htt", "httest"),
        ("htb", "httest"),
        ("http", "http"),
        ("hurl", "hurl"),
        // TODO: could be whatever the hell is virata
        ("hw", "php"),
        ("module", "php"),
        ("pkg", "php"),
        ("hy", "hy"),
        ("iba", "ibasic"),
        ("ibi", "ibasic"),
        ("icn", "icon"),
        // TODO: could be msidl
        ("idl", "idl"),
        ("idr", "idris2"),
        // TODO: could be many things
        ("inc", "php"),
        ("inf", "inform"),
        ("INF", "inform"),
        ("ii", "initng"),
        ("inko", "inko"),
        // TODO: could be other things
        ("inp", "tex"),
        // TODO: could be xmath
        ("ms", "nroff"),
        ("ipkg", "ipkg"),
        ("iss", "iss"),
        ("mst", "ist"),
        ("ist", "ist"),
        ("ijs", "j"),
        ("JAL", "jal"),
        ("jal", "jal"),
        ("jpr", "jam"),
        ("jpl", "jam"),
        ("janet", "janet"),
        ("jav", "java"),
        ("java", "java"),
        ("jsh", "java"),
        ("jj", "javacc"),
        ("jjt", "javacc"),
        ("es", "javascript"),
        ("mjs", "javascript"),
        ("javascript", "javascript"),
        ("js", "javascript"),
        ("jsm", "javascript"),
        ("cjs", "javascript"),
        ("jsx", "javascriptreact"),
        ("clp", "jess"),
        ("jgr", "jgraph"),
        ("jinja", "jinja"),
        ("jjdescription", "jjdescription"),
        ("j73", "jovial"),
        ("jov", "jovial"),
        ("jovial", "jovial"),
        ("properties", "jproperties"),
        ("jq", "jq"),
        ("slnf", "json"),
        ("json", "json"),
        ("jsonp", "json"),
        ("geojson", "json"),
        ("mcmeta", "json"),
        ("webmanifest", "json"),
        ("ipynb", "json"),
        ("jupyterlab-settings", "json"),
        ("sublime-project", "json"),
        ("sublime-settings", "json"),
        ("sublime-workspace", "json"),
        ("json-patch", "json"),
        ("bd", "json"),
        ("bda", "json"),
        ("xci", "json"),
        ("json5", "json5"),
        ("jsonc", "jsonc"),
        ("jsonl", "jsonl"),
        ("jsonnet", "jsonnet"),
        ("libsonnet", "jsonnet"),
        ("jsp", "jsp"),
        ("jl", "julia"),
        ("just", "just"),
        ("Just", "just"),
        ("JUST", "just"),
        ("kl", "karel"),
        ("KL", "karel"),
        ("kdl", "kdl"),
        ("kv", "kivy"),
        ("kix", "kix"),
        ("kts", "kotlin"),
        ("kt", "kotlin"),
        ("ktm", "kotlin"),
        ("sub", "krl"),
        ("Sub", "krl"),
        ("SUB", "krl"),
        ("ks", "kscript"),
        ("k", "kwt"),
        ("ACE", "lace"),
        ("ace", "lace"),
        ("lalrpop", "lalrpop"),
        ("latte", "latte"),
        ("lte", "latte"),
        ("ld", "ld"),
        ("ldif", "ldif"),
        ("lean", "lean"),
        ("journal", "ledger"),
        ("ldg", "ledger"),
        ("ledger", "ledger"),
        ("leo", "leo"),
        ("less", "less"),
        ("lex", "lex"),
        ("lxx", "lex"),
        ("l++", "lex"),
        ("l", "lex"),
        ("lhs", "lhaskell"),
        ("lidr", "lidris2"),
        ("ly", "lilypond"),
        ("ily", "lilypond"),
        ("liquid", "liquid"),
        ("liq", "liquidsoap"),
        ("L", "lisp"),
        ("lisp", "lisp"),
        ("el", "lisp"),
        ("lsp", "lisp"),
        ("asd", "lisp"),
        ("lt", "lite"),
        ("lite", "lite"),
        ("livemd", "livebook"),
        // TODO: could be lifelines
        ("ll", "llvm"),
        // TODO: could be other things
        ("log", "upstreamlog"),
        ("Log", "upstreamlog"),
        ("LOG", "upstreamlog"),
        ("lgt", "logtalk"),
        ("lotos", "lotos"),
        // TODO: could be lotos
        ("lot", "tex"),
        ("lout", "lout"),
        ("lou", "lout"),
        ("ulpc", "lpc"),
        ("lpc", "lpc"),
        // TODO: could be lpc
        ("c", "c"),
        // TODO: could be larch
        ("lsl", "lsl"),
        ("lss", "lss"),
        ("nse", "lua"),
        ("rockspec", "lua"),
        ("lua", "lua"),
        ("tlu", "lua"),
        ("luau", "luau"),
        ("lrc", "lyrics"),
        // TODO: one of the most ambiguous ones
        ("m", "matlab"),
        ("at", "m4"),
        // TODO: could be msmessages
        ("mc", "m4"),
        ("quake", "m3quake"),
        // TODO: idek
        ("m4", "m4"),
        ("eml", "mail"),
        // TODO: could be other flavors of make
        ("mk", "make"),
        ("mak", "make"),
        ("page", "mallard"),
        // TODO: could be lnkmap
        ("map", "map"),
        ("mws", "maple"),
        ("mpl", "maple"),
        ("mv", "maple"),
        // TODO: could be fake markdowns
        ("mkdn", "markdown"),
        ("md", "markdown"),
        ("mdwn", "markdown"),
        ("mkd", "markdown"),
        ("markdown", "markdown"),
        ("mdown", "markdown"),
        ("masm", "masm"),
        ("mhtml", "mason"),
        ("mason", "mason"),
        ("master", "master"),
        ("mas", "master"),
        ("demo", "maxima"),
        ("dm1", "maxima"),
        ("dm2", "maxima"),
        ("dm3", "maxima"),
        ("dmt", "maxima"),
        ("wxm", "maxima"),
        ("mbsyncrc", "mbsync"),
        ("mw", "mediawiki"),
        ("wiki", "mediawiki"),
        ("mel", "mel"),
        ("mmd", "mermaid"),
        ("mmdc", "mermaid"),
        ("mermaid", "mermaid"),
        ("mf", "mf"),
        ("mgl", "mgl"),
        ("mgp", "mgp"),
        ("my", "mib"),
        ("mib", "mib"),
        ("mix", "mix"),
        ("mixal", "mix"),
        ("mlir", "mlir"),
        // TODO: could be nroff
        ("mm", "objc"),
        ("nb", "mma"),
        ("wl", "mma"),
        ("mmp", "mmp"),
        // TODO: could be mmix
        ("mms", "make"),
        // TODO: could be many things
        ("mod", "gomod"),
        ("Mod", "gomod"),
        ("MOD", "gomod"),
        ("DEF", "modula2"),
        ("m3", "modula3"),
        ("i3", "modula3"),
        ("mg", "modula3"),
        ("ig", "modula3"),
        ("lm3", "modula3"),
        ("mojo", "mojo"),
        ("🔥", "mojo"), // 🙄
        ("ssc", "monk"),
        ("monk", "monk"),
        ("tsc", "monk"),
        ("isc", "monk"),
        ("moo", "moo"),
        ("moon", "moonscript"),
        ("move", "move"),
        ("mp", "mp"),
        // TODO: idek
        ("mpiv", "mp"),
        ("mpvi", "mp"),
        ("mpxl", "mp"),
        ("mof", "msidl"),
        ("odl", "msidl"),
        ("msql", "msql"),
        ("mss", "mss"),
        ("mu", "mupad"),
        ("mush", "mush"),
        ("mustache", "mustache"),
        ("mysql", "mysql"),
        ("n1ql", "n1ql"),
        ("nql", "n1ql"),
        ("nanorc", "nanorc"),
        ("nasm", "nasm"),
        ("NSA", "natural"),
        ("NSC", "natural"),
        ("NSG", "natural"),
        ("NSL", "natural"),
        ("NSM", "natural"),
        ("NSN", "natural"),
        ("NSP", "natural"),
        ("NSS", "natural"),
        ("ncf", "ncf"),
        ("nginx", "nginx"),
        ("nim", "nim"),
        ("nims", "nim"),
        ("nimble", "nim"),
        ("ninja", "ninja"),
        ("nix", "nix"),
        ("norg", "norg"),
        ("nqc", "nqc"),
        // TODO: nil-ing i guess?
        ("0", "nroff"),
        ("1", "nroff"),
        ("2", "nroff"),
        ("3", "nroff"),
        ("4", "nroff"),
        ("5", "nroff"),
        ("6", "nroff"),
        ("7", "nroff"),
        ("8", "nroff"),
        ("9", "nroff"),
        ("0p", "nroff"),
        ("1p", "nroff"),
        ("3p", "nroff"),
        ("1x", "nroff"),
        ("2x", "nroff"),
        ("3x", "nroff"),
        ("4x", "nroff"),
        ("5x", "nroff"),
        ("6x", "nroff"),
        ("7x", "nroff"),
        ("8x", "nroff"),
        ("3am", "nroff"),
        ("3perl", "nroff"),
        ("3pm", "nroff"),
        ("3posix", "nroff"),
        ("3type", "nroff"),
        ("n", "nroff"),
        ("roff", "nroff"),
        ("tmac", "nroff"),
        ("man", "nroff"),
        ("mom", "nroff"),
        ("nr", "nroff"),
        ("tr", "nroff"),
        ("nsi", "nsis"),
        ("nsh", "nsis"),
        ("nt", "ntriples"),
        ("nu", "nu"),
        ("obj", "obj"),
        ("objdump", "objdump"),
        ("cppobjdump", "objdump"),
        ("obl", "obse"),
        ("obse", "obse"),
        ("oblivion", "obse"),
        ("obscript", "obse"),
        ("mlt", "ocaml"),
        ("mly", "ocaml"),
        ("mll", "ocaml"),
        ("mlp", "ocaml"),
        ("mlip", "ocaml"),
        ("mli", "ocaml"),
        ("ml", "ocaml"),
        ("occ", "occam"),
        ("odin", "odin"),
        ("xom", "omnimark"),
        ("xin", "omnimark"),
        ("opam", "opam"),
        ("or", "openroad"),
        ("scad", "openscad"),
        ("ovpn", "openvpn"),
        ("opl", "opl"),
        ("opL", "opl"),
        ("oPl", "opl"),
        ("oPL", "opl"),
        ("Opl", "opl"),
        ("OpL", "opl"),
        ("OPl", "opl"),
        ("OPL", "opl"),
        ("ora", "ora"),
        ("org", "org"),
        ("org_archive", "org"),
        ("pandoc", "pandoc"),
        ("pdk", "pandoc"),
        ("pd", "pandoc"),
        ("pdc", "pandoc"),
        ("pxsl", "papp"),
        ("papp", "papp"),
        ("pxml", "papp"),
        ("pas", "pascal"),
        // TODO: could be pascal
        ("lpr", "xml"),
        ("dpr", "pascal"),
        ("txtpb", "pbtxt"),
        ("textproto", "pbtxt"),
        ("textpb", "pbtxt"),
        ("pbtxt", "pbtxt"),
        ("g", "pccts"),
        ("pcmk", "pcmk"),
        ("pdf", "pdf"),
        ("pem", "pem"),
        ("cer", "pem"),
        ("crt", "pem"),
        ("csr", "pem"),
        ("plx", "perl"),
        ("prisma", "prisma"),
        ("psgi", "perl"),
        ("al", "perl"),
        ("ctp", "php"),
        ("php", "php"),
        ("phpt", "php"),
        ("php0", "php"),
        ("php1", "php"),
        ("php2", "php"),
        ("php3", "php"),
        ("php4", "php"),
        ("php5", "php"),
        ("php6", "php"),
        ("php7", "php"),
        ("php8", "php"),
        ("php9", "php"),
        ("phtml", "php"),
        ("theme", "php"),
        ("pike", "pike"),
        ("pmod", "pike"),
        ("rcp", "pilrc"),
        // TODO: could be prolog
        ("PL", "perl"),
        ("pli", "pli"),
        ("pl1", "pli"),
        ("p36", "plm"),
        ("plm", "plm"),
        ("pac", "plm"),
        ("plp", "plp"),
        ("pls", "plsql"),
        ("plsql", "plsql"),
        ("po", "po"),
        ("pot", "po"),
        ("pod", "pod"),
        ("filter", "poefilter"),
        ("pk", "poke"),
        ("pony", "pony"),
        ("ps", "postscr"),
        ("epsi", "postscr"),
        ("afm", "postscr"),
        ("epsf", "postscr"),
        ("eps", "postscr"),
        ("pfa", "postscr"),
        ("ai", "postscr"),
        ("pov", "pov"),
        ("ppd", "ppd"),
        ("it", "ppwiz"),
        ("ih", "ppwiz"),
        ("pq", "pq"),
        ("action", "privoxy"),
        // TODO: could be clipper
        ("prg", "rapid"),
        ("Prg", "rapid"),
        ("PRG", "rapid"),
        ("pc", "proc"),
        ("pdb", "prolog"),
        ("pml", "promela"),
        ("proto", "proto"),
        ("prql", "prql"),
        ("psd1", "ps1"),
        ("psm1", "ps1"),
        ("ps1", "ps1"),
        ("pssc", "ps1"),
        ("ps1xml", "ps1xml"),
        ("psf", "psf"),
        ("psl", "psl"),
        ("ptx", "ptx"),
        ("pug", "pug"),
        ("purs", "purescript"),
        ("arr", "pyret"),
        ("pxd", "pyrex"),
        ("pxi", "pyrex"),
        ("pyx", "pyrex"),
        ("pyx+", "pyrex"),
        ("pyw", "python"),
        ("py", "python"),
        ("pyi", "python"),
        ("ptl", "python"),
        ("ipy", "python"),
        ("ql", "ql"),
        ("qll", "ql"),
        ("qml", "qml"),
        ("qbs", "qml"),
        ("qmd", "quarto"),
        // TODO: could be other things
        ("R", "r"),
        ("rkt", "racket"),
        ("rktd", "racket"),
        ("rktl", "racket"),
        ("rad", "radiance"),
        ("mat", "radiance"),
        ("pod6", "raku"),
        ("rakudoc", "raku"),
        ("rakutest", "raku"),
        ("rakumod", "raku"),
        ("pm6", "raku"),
        ("raku", "raku"),
        ("t6", "raku"),
        ("p6", "raku"),
        ("raml", "raml"),
        ("sysx", "rapid"),
        ("sysX", "rapid"),
        ("Sysx", "rapid"),
        ("SysX", "rapid"),
        ("SYSX", "rapid"),
        ("SYSx", "rapid"),
        ("modx", "rapid"),
        ("modX", "rapid"),
        ("Modx", "rapid"),
        ("ModX", "rapid"),
        ("MODX", "rapid"),
        ("MODx", "rapid"),
        ("rasi", "rasi"),
        ("rbs", "rbs"),
        ("rego", "rego"),
        ("rem", "remind"),
        ("remind", "remind"),
        ("pip", "requirements"),
        ("res", "rescript"),
        ("resi", "rescript"),
        ("frt", "reva"),
        ("testUnit", "rexx"),
        ("rex", "rexx"),
        ("orx", "rexx"),
        ("rexx", "rexx"),
        ("jrexx", "rexx"),
        ("rxj", "rexx"),
        ("rexxj", "rexx"),
        ("testGroup", "rexx"),
        ("rxo", "rexx"),
        ("Rd", "rhelp"),
        ("rd", "rhelp"),
        ("rib", "rib"),
        ("Rmd", "rmd"),
        ("rmd", "rmd"),
        ("smd", "rmd"),
        ("Smd", "rmd"),
        ("rnc", "rnc"),
        ("rng", "rng"),
        ("rnw", "rnoweb"),
        ("snw", "rnoweb"),
        ("Rnw", "rnoweb"),
        ("Snw", "rnoweb"),
        ("robot", "robot"),
        ("resource", "robot"),
        ("roc", "roc"),
        ("ron", "ron"),
        ("rsc", "routeros"),
        ("x", "rpcgen"),
        ("rpgle", "rpgle"),
        ("rpgleinc", "rpgle"),
        ("rpl", "rpl"),
        ("Srst", "rrst"),
        ("srst", "rrst"),
        ("Rrst", "rrst"),
        ("rrst", "rrst"),
        ("rst", "rst"),
        ("rtf", "rtf"),
        ("rjs", "ruby"),
        ("rxml", "ruby"),
        ("rb", "ruby"),
        ("rant", "ruby"),
        ("ru", "ruby"),
        ("rbw", "ruby"),
        ("gemspec", "ruby"),
        ("builder", "ruby"),
        ("rake", "ruby"),
        ("rs", "rust"),
        // TODO: could be sather
        ("sa", "tiasm"),
        ("sage", "sage"),
        ("sls", "salt"),
        ("sas", "sas"),
        ("sass", "sass"),
        ("sbt", "sbt"),
        ("scala", "scala"),
        ("mill", "scala"),
        ("ss", "scheme"),
        ("scm", "scheme"),
        ("sld", "scheme"),
        ("stsg", "scheme"),
        ("sce", "scilab"),
        ("sci", "scilab"),
        ("scss", "scss"),
        ("sd", "sd"),
        ("sdc", "sdc"),
        ("pr", "sdl"),
        ("sdl", "sdl"),
        ("sed", "sed"),
        ("sexp", "sexplib"),
        // TODO: #! /bin/{other shells i asume}
        ("bash", "bash"),
        ("bats", "bash"),
        ("cygport", "bash"),
        ("ebuild", "bash"),
        ("eclass", "bash"),
        ("env", "bash"),
        ("envrc", "bash"),
        ("ksh", "ksh"),
        ("sh", "bash"),
        ("lo", "sh"),
        ("la", "sh"),
        ("lai", "sh"),
        ("mdd", "sh"),
        ("slang", "shaderslang"),
        ("sieve", "sieve"),
        ("siv", "sieve"),
        // TODO: could be lprolog
        ("sig", "sml"),
        // TODO: could be sile
        ("sil", "sil"),
        ("sim", "simula"),
        ("s85", "sinda"),
        ("sin", "sinda"),
        ("ssm", "sisu"),
        ("sst", "sisu"),
        ("ssi", "sisu"),
        ("_sst", "sisu"),
        ("-sst", "sisu"),
        ("il", "skill"),
        ("ils", "skill"),
        ("cdf", "skill"),
        ("sl", "slang"),
        ("ice", "slice"),
        ("slint", "slint"),
        ("score", "slrnsc"),
        ("sol", "solidity"),
        ("smali", "smali"),
        ("tpl", "smarty"),
        ("ihlp", "smcl"),
        ("smcl", "smcl"),
        ("hlp", "smcl"),
        ("smith", "smith"),
        ("smt", "smith"),
        ("smithy", "smithy"),
        ("sml", "sml"),
        ("smk", "snakemake"),
        ("spt", "snobol4"),
        ("sno", "snobol4"),
        ("sln", "solution"),
        ("sparql", "sparql"),
        ("rq", "sparql"),
        ("spec", "spec"),
        ("spice", "spice"),
        ("sp", "spice"),
        ("spd", "spup"),
        ("spdata", "spup"),
        ("speedup", "spup"),
        ("spi", "spyce"),
        ("spy", "spyce"),
        ("tyc", "sql"),
        // TODO: could be sql, but I'm biased
        ("typ", "typst"),
        ("pkb", "sql"),
        ("tyb", "sql"),
        ("pks", "sql"),
        ("sqlj", "sqlj"),
        ("sqi", "sqr"),
        ("sqr", "sqr"),
        ("nut", "squirrel"),
        // TODO: could be other things
        ("src", "krl"),
        ("Src", "krl"),
        ("SRC", "krl"),
        ("s28", "srec"),
        ("s37", "srec"),
        ("srec", "srec"),
        ("mot", "srec"),
        ("s19", "srec"),
        ("srt", "srt"),
        ("ssa", "ssa"),
        ("ass", "ssa"),
        ("st", "st"),
        ("ipd", "starlark"),
        ("star", "starlark"),
        ("starlark", "starlark"),
        ("imata", "stata"),
        ("do", "stata"),
        ("mata", "stata"),
        ("ado", "stata"),
        ("stp", "stp"),
        ("styl", "stylus"),
        ("stylus", "stylus"),
        ("quark", "supercollider"),
        ("sface", "surface"),
        ("svelte", "svelte"),
        ("svg", "svg"),
        ("sw", "sway"),
        ("swift", "swift"),
        ("swiftinterface", "swift"),
        ("swig", "swig"),
        ("swg", "swig"),
        // TODO: could be rapid
        ("sys", "bat"),
        ("Sys", "bat"),
        ("SYS", "bat"),
        ("svh", "systemverilog"),
        ("sv", "systemverilog"),
        ("cmm", "trace32"),
        ("cmmt", "trace32"),
        ("t32", "trace32"),
        ("td", "tablegen"),
        ("tak", "tak"),
        ("tal", "tal"),
        ("task", "taskedit"),
        ("tm", "tcl"),
        ("tcl", "tcl"),
        ("itk", "tcl"),
        ("itcl", "tcl"),
        ("tk", "tcl"),
        ("jacl", "tcl"),
        ("tl", "teal"),
        ("templ", "templ"),
        ("tmpl", "template"),
        ("tera", "tera"),
        ("ti", "terminfo"),
        ("dtx", "tex"),
        ("ltx", "tex"),
        ("bbl", "tex"),
        ("latex", "tex"),
        ("sty", "tex"),
        ("pgf", "tex"),
        ("nlo", "tex"),
        ("nls", "tex"),
        ("thm", "tex"),
        ("eps_tex", "tex"),
        ("pdf_tex", "tex"),
        ("pygtex", "tex"),
        ("pygstyle", "tex"),
        ("clo", "tex"),
        ("aux", "tex"),
        ("brf", "tex"),
        ("ind", "tex"),
        ("lof", "tex"),
        ("loe", "tex"),
        ("nav", "tex"),
        ("vrb", "tex"),
        ("ins", "tex"),
        ("tikz", "tex"),
        ("bbx", "tex"),
        ("cbx", "tex"),
        ("beamer", "tex"),
        // TODO: could be many things
        ("cls", "st"),
        ("texi", "texinfo"),
        ("txi", "texinfo"),
        ("texinfo", "texinfo"),
        ("text", "text"),
        ("tfvars", "terraform-vars"),
        ("thrift", "thrift"),
        ("tla", "tla"),
        ("tli", "tli"),
        ("toml", "toml"),
        ("tpp", "tpp"),
        ("treetop", "treetop"),
        ("trig", "trig"),
        ("slt", "tsalt"),
        ("tsscl", "tsscl"),
        ("tssgm", "tssgm"),
        ("tssop", "tssop"),
        ("tsv", "tsv"),
        ("tutor", "tutor"),
        ("twig", "twig"),
        // TODO: could be sql (greedy ahh language)
        ("ts", "typescript"),
        ("mts", "typescript"),
        ("cts", "typescript"),
        ("tsx", "typescriptreact"),
        ("tsp", "typespec"),
        ("uc", "uc"),
        ("uit", "uil"),
        ("uil", "uil"),
        ("ungram", "ungrammar"),
        ("u", "unison"),
        ("uu", "unison"),
        ("url", "urlshortcut"),
        ("usd", "usd"),
        ("usda", "usd"),
        // TODO: could be coq (🤤)
        ("v", "v"),
        ("vsh", "v"),
        ("vv", "v"),
        ("ctl", "vb"),
        ("dob", "vb"),
        ("dsm", "vb"),
        ("dsr", "vb"),
        ("pag", "vb"),
        ("sba", "vb"),
        ("vb", "vb"),
        ("vbs", "vb"),
        // TODO: could be vim (???)
        ("vba", "vb"),
        ("vdf", "vdf"),
        ("vdmpp", "vdmpp"),
        ("vpp", "vdmpp"),
        ("vdmrt", "vdmrt"),
        ("vdmsl", "vdmsl"),
        ("vdm", "vdmsl"),
        ("vto", "vento"),
        ("vr", "vera"),
        ("vri", "vera"),
        ("vrh", "vera"),
        ("va", "verilogams"),
        ("vams", "verilogams"),
        ("vhdl", "vhdl"),
        ("vst", "vhdl"),
        ("vhd", "vhdl"),
        ("hdl", "vhdl"),
        ("vho", "vhdl"),
        ("vbe", "vhdl"),
        ("tape", "vhs"),
        ("vim", "vim"),
        ("mar", "vmasm"),
        ("cm", "voscm"),
        ("wrl", "vrml"),
        ("vroom", "vroom"),
        ("vue", "vue"),
        ("wast", "wat"),
        ("wat", "wat"),
        ("wdl", "wdl"),
        ("wm", "webmacro"),
        ("wgsl", "wgsl"),
        ("wbt", "winbatch"),
        ("wit", "wit"),
        ("wml", "wml"),
        ("wsf", "wsh"),
        ("wsc", "wsh"),
        ("wsml", "wsml"),
        ("ad", "xdefaults"),
        ("xhtml", "xhtml"),
        ("xht", "xhtml"),
        ("msc", "xmath"),
        ("msf", "xmath"),
        ("psc1", "xml"),
        ("tpm", "xml"),
        ("xliff", "xml"),
        ("atom", "xml"),
        ("xul", "xml"),
        ("cdxml", "xml"),
        ("mpd", "xml"),
        ("rss", "xml"),
        ("fsproj", "xml"),
        ("ui", "xml"),
        ("vbproj", "xml"),
        ("xlf", "xml"),
        ("wsdl", "xml"),
        ("csproj", "xml"),
        ("wpl", "xml"),
        ("xmi", "xml"),
        ("xpr", "xml"),
        ("xpfm", "xml"),
        ("spfm", "xml"),
        ("bxml", "xml"),
        ("mmi", "xml"),
        ("xcu", "xml"),
        ("xlb", "xml"),
        ("xlc", "xml"),
        ("xba", "xml"),
        ("slnx", "xml"),
        // TODO: could be xpm2 or XPM2 (which are obviously not the same things)
        ("xpm", "xpm"),
        ("xpm2", "xpm2"),
        ("xqy", "xquery"),
        ("xqm", "xquery"),
        ("xquery", "xquery"),
        ("xq", "xquery"),
        ("xql", "xquery"),
        ("xs", "xs"),
        ("xsd", "xsd"),
        ("xsl", "xslt"),
        ("xslt", "xslt"),
        ("yy", "yacc"),
        ("y++", "yacc"),
        ("yxx", "yacc"),
        ("yml", "yaml"),
        ("yaml", "yaml"),
        ("eyaml", "yaml"),
        ("mplstyle", "yaml"),
        // TODO: could be xml
        ("grc", "yaml"),
        ("yang", "yang"),
        ("yuck", "yuck"),
        ("z8a", "z8a"),
        ("zig", "zig"),
        ("zon", "zig"),
        ("ziggy", "ziggy"),
        ("ziggy-schema", "ziggy_schema"),
        ("zu", "zimbu"),
        ("zut", "zimbutempl"),
        ("zs", "zserio"),
        ("zsh", "zsh"),
        ("zunit", "zsh"),
        ("zsh-theme", "zsh"),
        ("vala", "vala"),
        // TODO: could be winbatch
        ("web", "web"),
        // TODO: could be prolog
        ("pl", "perl"),
        // TODO: could be puppet
        ("pp", "pascal"),
        // TODO: could be swig 🍺
        ("i", "progress"),
        // TODO: could be cweb
        ("w", "progress"),
        // TODO: could be progress
        ("p", "pascal"),
        // TODO: could be other things
        ("pro", "prolog"),
        // TODO: could be patch
        ("patch", "diff"),
        // TODO: could be rexx
        ("r", "r"),
        // TODO: nil-ing i guess?
        ("rdf", "redif"),
        // TODO: AAAAAAAAAAAAAAAAAA
        ("rules", "javascript"),
        // TODO: could be superdupermegahypercolider
        ("sc", "scala"),
        // TODO: could be superdupermegahypercolider as well
        ("scd", "scdoc"),
        // TODO: idek
        ("tcsh", "tcsh"),
        // TODO: could be other sql flavors
        ("sql", "sql"),
        ("zsql", "sql"),
        // TODO: could be other tex flavors
        ("tex", "tex"),
        // TODO: could be terraform
        ("tf", "tf"),
        // TODO: which languages dare?
        ("txt", "text"),
        // TODO: could be other, secret xmls
        ("xml", "xml"),
        // TODO: racc is not yacc, bro
        ("y", "yacc"),
        // TODO: could be other irrelevant things
        ("cmd", "dosbatch"),
        // TODO: could be diva 💅
        ("rul", "ishd"),
        // TODO: could be cobol
        ("cpy", "python"),
        // TODO: could be structurizr
        ("dsl", "dsl"),
        // TODO: could be xml
        ("smil", "smil"),
        // TODO: could be mib 🕴
        ("smi", "smil"),
        // TODO: could be php
        ("install", "bash"),
        // TODO: could be the infamous xpm or its dastardly cousin, xpm2
        ("pm", "perl"),
        // TODO: could be nroff, again
        ("me", "objcpp"),
        // TODO: nil-ing i guess?
        ("reg", "registry"),
        // TODO: could be turtle 🐢
        ("ttl", "terraterm"),
        // TODO: could not be muttrc
        ("rc", "rc"),
        ("rch", "rc"),
        // TODO: nil-ing i guess?
        ("class", "scala"),
        // TODO: could be other things
        ("sgml", "sgml"),
        ("sgm", "sgml"),
        // TODO: could be nroff or tads
        ("t", "perl"),
        // No match means there is no clear language
        ("bak", ""),
        ("dpkg-bak", ""),
        ("dpkg-dist", ""),
        ("dpkg-old", ""),
        ("dpkg-new", ""),
        ("in", ""),
        ("new", ""),
        ("old", ""),
        ("orig", ""),
        ("pacsave", ""),
        ("pacnew", ""),
        ("rpmsave", ""),
        ("rmpnew", ""),
    ])
});

static FILENAMES: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
    HashMap::from_iter([
        ("a2psrc", "a2ps"),
        ("/etc/a2ps.cfg", "a2ps"),
        (".a2psrc", "a2ps"),
        (".asoundrc", "alsaconf"),
        ("/usr/share/alsa/alsa.conf", "alsaconf"),
        ("/etc/asound.conf", "alsaconf"),
        ("build.xml", "ant"),
        (".htaccess", "apache"),
        ("APKBUILD", "apkbuild"),
        ("apt.conf", "aptconf"),
        ("/.aptitude/config", "aptconf"),
        ("=tagging-method", "arch"),
        (".arch-inventory", "arch"),
        ("makefile.am", "automake"),
        ("Makefile.am", "automake"),
        ("GNUmakefile.am", "automake"),
        (".bash_aliases", "bash"),
        (".bash-aliases", "bash"),
        (".bash_history", "bash"),
        (".bash-history", "bash"),
        (".bash_logout", "bash"),
        (".bash-logout", "bash"),
        (".bash_profile", "bash"),
        (".bash-profile", "bash"),
        ("named.root", "bindzone"),
        ("WORKSPACE", "bzl"),
        ("WORKSPACE.bzlmod", "bzl"),
        ("BUCK", "bzl"),
        ("BUILD", "bzl"),
        ("cabal.project", "cabalproject"),
        ("cabal.config", "cabalconfig"),
        ("calendar", "calendar"),
        ("catalog", "catalog"),
        ("/etc/cdrdao.conf", "cdrdaoconf"),
        (".cdrdao", "cdrdaoconf"),
        ("/etc/default/cdrdao", "cdrdaoconf"),
        ("/etc/defaults/cdrdao", "cdrdaoconf"),
        ("cfengine.conf", "cfengine"),
        ("cgdbrc", "cgdbrc"),
        ("init.trans", "clojure"),
        (".trans", "clojure"),
        ("CMakeLists.txt", "cmake"),
        ("CMakeCache.txt", "cmakecache"),
        (".cling_history", "cpp"),
        (".alias", "csh"),
        (".cshrc", "csh"),
        (".login", "csh"),
        ("csh.cshrc", "csh"),
        ("csh.login", "csh"),
        ("csh.logout", "csh"),
        ("auto.master", "conf"),
        ("texdoc.cnf", "conf"),
        (".x11vncrc", "conf"),
        (".chktexrc", "conf"),
        (".ripgreprc", "conf"),
        ("ripgreprc", "conf"),
        ("configure.in", "config"),
        ("configure.ac", "config"),
        ("crontab", "crontab"),
        (".cvsrc", "cvsrc"),
        ("/debian/changelog", "debchangelog"),
        ("changelog.dch", "debchangelog"),
        ("changelog.Debian", "debchangelog"),
        ("NEWS.dch", "debchangelog"),
        ("NEWS.Debian", "debchangelog"),
        ("/debian/control", "debcontrol"),
        ("/DEBIAN/control", "debcontrol"),
        ("/debian/copyright", "debcopyright"),
        ("/etc/apt/sources.list", "debsources"),
        ("denyhosts.conf", "denyhosts"),
        ("dict.conf", "dictconf"),
        (".dictrc", "dictconf"),
        ("/etc/DIR_COLORS", "dircolors"),
        (".dir_colors", "dircolors"),
        (".dircolors", "dircolors"),
        ("/etc/dnsmasq.conf", "dnsmasq"),
        ("Containerfile", "dockerfile"),
        ("dockerfile", "dockerfile"),
        ("Dockerfile", "dockerfile"),
        ("npmrc", "dosini"),
        ("/etc/yum.conf", "dosini"),
        (".npmrc", "dosini"),
        ("pip.conf", "dosini"),
        ("setup.cfg", "dosini"),
        ("pudb.cfg", "dosini"),
        (".coveragerc", "dosini"),
        (".pypirc", "dosini"),
        (".pylintrc", "dosini"),
        ("pylintrc", "dosini"),
        (".replyrc", "dosini"),
        (".gitlint", "dosini"),
        (".oelint.cfg", "dosini"),
        ("psprint.conf", "dosini"),
        ("sofficerc", "dosini"),
        ("mimeapps.list", "dosini"),
        (".wakatime.cfg", "dosini"),
        ("nfs.conf", "dosini"),
        ("nfsmount.conf", "dosini"),
        (".notmuch-config", "dosini"),
        (".alsoftrc", "dosini"),
        ("alsoft.conf", "dosini"),
        ("alsoft.ini", "dosini"),
        ("alsoftrc.sample", "dosini"),
        ("pacman.conf", "confini"),
        ("paru.conf", "confini"),
        ("mpv.conf", "confini"),
        ("dune", "dune"),
        ("jbuild", "dune"),
        ("dune-workspace", "dune"),
        ("dune-project", "dune"),
        ("dune-file", "dune"),
        ("Earthfile", "earthfile"),
        (".editorconfig", "editorconfig"),
        ("elinks.conf", "elinks"),
        ("mix.lock", "elixir"),
        ("filter-rules", "elmfilt"),
        ("exim.conf", "exim"),
        ("exports", "exports"),
        ("fennelrc", "fennel"),
        (".fennelrc", "fennel"),
        (".fetchmailrc", "fetchmail"),
        // TODO: nil-ing i guess?
        ("fvSchemes", "foam"),
        ("fvSolution", "foam"),
        ("fvConstraints", "foam"),
        ("fvModels", "foam"),
        ("fstab", "fstab"),
        ("mtab", "fstab"),
        (".gdbinit", "gdb"),
        ("gdbinit", "gdb"),
        (".gdbearlyinit", "gdb"),
        ("gdbearlyinit", "gdb"),
        ("lltxxxxx.txt", "gedcom"),
        ("TAG_EDITMSG", "gitcommit"),
        ("MERGE_MSG", "gitcommit"),
        ("COMMIT_EDITMSG", "gitcommit"),
        ("NOTES_EDITMSG", "gitcommit"),
        ("EDIT_DESCRIPTION", "gitcommit"),
        (".gitconfig", "gitconfig"),
        (".gitmodules", "gitconfig"),
        (".gitattributes", "gitattributes"),
        (".gitignore", "gitignore"),
        (".ignore", "gitignore"),
        (".containerignore", "gitignore"),
        (".dockerignore", "gitignore"),
        (".fdignore", "gitignore"),
        (".npmignore", "gitignore"),
        (".rgignore", "gitignore"),
        (".vscodeignore", "gitignore"),
        ("gitolite.conf", "gitolite"),
        ("git-rebase-todo", "gitrebase"),
        ("gkrellmrc", "gkrellmrc"),
        (".gnashrc", "gnash"),
        (".gnashpluginrc", "gnash"),
        ("gnashpluginrc", "gnash"),
        ("gnashrc", "gnash"),
        (".gnuplot_history", "gnuplot"),
        ("goaccess.conf", "goaccess"),
        ("go.sum", "gosum"),
        ("go.work.sum", "gosum"),
        ("go.work", "gowork"),
        (".gprc", "gp"),
        ("/.gnupg/gpg.conf", "gpg"),
        ("/.gnupg/options", "gpg"),
        ("Jenkinsfile", "groovy"),
        ("/var/backups/gshadow.bak", "group"),
        ("/etc/gshadow", "group"),
        ("/etc/group-", "group"),
        ("/etc/gshadow.edit", "group"),
        ("/etc/gshadow-", "group"),
        ("/etc/group", "group"),
        ("/var/backups/group.bak", "group"),
        ("/etc/group.edit", "group"),
        ("/boot/grub/menu.lst", "grub"),
        ("/etc/grub.conf", "grub"),
        ("/boot/grub/grub.conf", "grub"),
        (".gtkrc", "gtkrc"),
        ("gtkrc", "gtkrc"),
        ("snort.conf", "hog"),
        ("vision.conf", "hog"),
        ("/etc/host.conf", "hostconf"),
        ("/etc/hosts.allow", "hostsaccess"),
        ("/etc/hosts.deny", "hostsaccess"),
        (".hy-history", "hy"),
        ("hyprland.conf", "hyprlang"),
        ("hyprpaper.conf", "hyprlang"),
        ("hypridle.conf", "hyprlang"),
        ("hyprlock.conf", "hyprlang"),
        ("/.icewm/menu", "icemenu"),
        (".indent.pro", "indent"),
        ("indentrc", "indent"),
        ("inittab", "inittab"),
        ("ipf.conf", "ipfilter"),
        ("ipf6.conf", "ipfilter"),
        ("ipf.rules", "ipfilter"),
        (".bun_repl_history", "javascript"),
        (".node_repl_history", "javascript"),
        ("deno_history.txt", "javascript"),
        ("Pipfile.lock", "json"),
        (".firebaserc", "json"),
        (".prettierrc", "json"),
        (".stylelintrc", "json"),
        (".lintstagedrc", "json"),
        ("deno.lock", "json"),
        ("flake.lock", "json"),
        (".swcrc", "json"),
        (".babelrc", "jsonc"),
        (".eslintrc", "jsonc"),
        (".hintrc", "jsonc"),
        (".jscsrc", "jsonc"),
        (".jsfmtrc", "jsonc"),
        (".jshintrc", "jsonc"),
        (".luaurc", "jsonc"),
        (".swrc", "jsonc"),
        (".vsconfig", "jsonc"),
        ("bun.lock", "jsonc"),
        (".justfile", "just"),
        (".Justfile", "just"),
        (".JUSTFILE", "just"),
        ("justfile", "just"),
        ("Justfile", "just"),
        ("JUSTFILE", "just"),
        ("Kconfig", "kconfig"),
        ("Kconfig.debug", "kconfig"),
        ("Config.in", "kconfig"),
        ("ldaprc", "ldapconf"),
        (".ldaprc", "ldapconf"),
        ("ldap.conf", "ldapconf"),
        ("lfrc", "lf"),
        ("lftp.conf", "lftp"),
        (".lftprc", "lftp"),
        ("/.libao", "libao"),
        ("/etc/libao.conf", "libao"),
        ("lilo.conf", "lilo"),
        ("/etc/limits", "limits"),
        (".emacs", "lisp"),
        ("sbclrc", "lisp"),
        (".sbclrc", "lisp"),
        (".sawfishrc", "lisp"),
        ("/etc/login.access", "loginaccess"),
        ("/etc/login.defs", "logindefs"),
        (".lsl", "lsl"),
        (".busted", "lua"),
        (".luacheckrc", "lua"),
        (".lua_history", "lua"),
        ("config.ld", "lua"),
        ("rock_manifest", "lua"),
        ("lynx.cfg", "lynx"),
        ("m3overrides", "m3build"),
        ("m3makefile", "m3build"),
        ("cm3.cfg", "m3quake"),
        (".m4_history", "m4"),
        (".followup", "mail"),
        (".article", "mail"),
        (".letter", "mail"),
        ("/etc/aliases", "mailaliases"),
        ("/etc/mail/aliases", "mailaliases"),
        ("mailcap", "mailcap"),
        (".mailcap", "mailcap"),
        ("Kbuild", "make"),
        ("/etc/man.conf", "manconf"),
        ("man.config", "manconf"),
        ("maxima-init.mac", "maxima"),
        ("isyncrc", "mbsync"),
        ("meson.build", "meson"),
        ("meson.options", "meson"),
        ("meson_options.txt", "meson"),
        ("/etc/conf.modules", "modconf"),
        ("/etc/modules", "modconf"),
        ("/etc/modules.conf", "modconf"),
        ("/.mplayer/config", "mplayerconf"),
        ("mplayer.conf", "mplayerconf"),
        ("mrxvtrc", "mrxvtrc"),
        (".mrxvtrc", "mrxvtrc"),
        (".msmtprc", "msmtp"),
        ("Muttngrc", "muttrc"),
        ("Muttrc", "muttrc"),
        (".mysql_history", "mysql"),
        ("/etc/nanorc", "nanorc"),
        ("Neomuttrc", "neomuttrc"),
        (".netrc", "netrc"),
        // TODO: nil-ing i guess?
        ("NEWS", "debchangelog"),
        (".ocamlinit", "ocaml"),
        (".octaverc", "octave"),
        ("octaverc", "octave"),
        ("octave.conf", "octave"),
        (".ondirrc", "ondir"),
        ("opam", "opam"),
        ("opam.locked", "opam"),
        ("/etc/pam.conf", "pamconf"),
        ("pam_env.conf", "pamenv"),
        (".pam_environment", "pamenv"),
        ("/var/backups/passwd.bak", "passwd"),
        ("/var/backups/shadow.bak", "passwd"),
        ("/etc/passwd", "passwd"),
        ("/etc/passwd-", "passwd"),
        ("/etc/shadow.edit", "passwd"),
        ("/etc/shadow-", "passwd"),
        ("/etc/shadow", "passwd"),
        ("/etc/passwd.edit", "passwd"),
        (".gitolite.rc", "perl"),
        ("gitolite.rc", "perl"),
        ("example.gitolite.rc", "perl"),
        ("latexmkrc", "perl"),
        (".latexmkrc", "perl"),
        ("pf.conf", "pf"),
        ("main.cf", "pfmain"),
        ("main.cf.proto", "pfmain"),
        ("pinerc", "pine"),
        (".pinercex", "pine"),
        (".pinerc", "pine"),
        ("pinercex", "pine"),
        ("/etc/pinforc", "pinfo"),
        ("/.pinforc", "pinfo"),
        (".povrayrc", "povini"),
        // TODO: idek
        ("printcap", "ptcap"),
        ("termcap", "ptcap"),
        (".procmailrc", "procmail"),
        (".procmail", "procmail"),
        // TODO: could be other things
        ("indent.pro", "cpp"),
        ("/etc/protocols", "protocols"),
        // TODO: nil-ing i guess?
        ("INDEX", "psf"),
        ("INFO", "psf"),
        ("MANIFEST.in", "pymanifest"),
        (".pythonstartup", "python"),
        (".pythonrc", "python"),
        (".python_history", "python"),
        (".jline-jython.history", "python"),
        ("SConstruct", "python"),
        ("qmldir", "qmldir"),
        (".Rhistory", "r"),
        (".Rprofile", "r"),
        ("Rprofile", "r"),
        ("Rprofile.site", "r"),
        ("ratpoisonrc", "ratpoison"),
        (".ratpoisonrc", "ratpoison"),
        ("inputrc", "readline"),
        (".inputrc", "readline"),
        (".reminders", "remind"),
        ("requirements.txt", "requirements"),
        ("constraints.txt", "requirements"),
        ("requirements.in", "requirements"),
        ("resolv.conf", "resolv"),
        ("robots.txt", "robots"),
        ("Gemfile", "ruby"),
        ("Puppetfile", "ruby"),
        (".irbrc", "ruby"),
        ("irbrc", "ruby"),
        (".irb_history", "ruby"),
        ("irb_history", "ruby"),
        ("rakefile", "ruby"),
        ("Rakefile", "ruby"),
        ("rantfile", "ruby"),
        ("Rantfile", "ruby"),
        ("Vagrantfile", "ruby"),
        ("smb.conf", "samba"),
        (".lips_repl_history", "scheme"),
        (".guile", "scheme"),
        ("screenrc", "screen"),
        (".screenrc", "screen"),
        ("/etc/sensors3.conf", "sensors"),
        ("/etc/sensors.conf", "sensors"),
        ("/etc/services", "services"),
        ("/etc/serial.conf", "setserial"),
        ("/etc/udev/cdsymlinks.conf", "sh"),
        (".ash_history", "sh"),
        (".devscripts", "sh"),
        ("devscripts.conf", "sh"),
        ("makepkg.conf", "sh"),
        (".makepkg.conf", "sh"),
        ("user-dirs.dirs", "sh"),
        ("user-dirs.defaults", "sh"),
        (".xprofile", "sh"),
        ("bash.bashrc", "bash"),
        ("bashrc", "bash"),
        (".bashrc", "bash"),
        (".kshrc", "ksh"),
        (".profile", "bash"),
        ("/etc/profile", "bash"),
        ("PKGBUILD", "bash"),
        (".tcshrc", "tcsh"),
        ("tcsh.login", "tcsh"),
        ("tcsh.tcshrc", "tcsh"),
        ("/etc/slp.conf", "slpconf"),
        ("/etc/slp.reg", "slpreg"),
        ("/etc/slp.spi", "slpspi"),
        (".slrnrc", "slrnrc"),
        ("sendmail.cf", "sm"),
        ("Snakefile", "snakemake"),
        (".sqlite_history", "sql"),
        ("squid.conf", "squid"),
        ("ssh_config", "sshconfig"),
        ("sshd_config", "sshdconfig"),
        ("/etc/sudoers", "sudoers"),
        ("sudoers.tmp", "sudoers"),
        ("/etc/sysctl.conf", "sysctl"),
        ("tags", "tags"),
        ("pending.data", "taskdata"),
        ("completed.data", "taskdata"),
        ("undo.data", "taskdata"),
        (".tclshrc", "tcl"),
        (".wishrc", "tcl"),
        (".tclsh-history", "tcl"),
        ("tclsh.rc", "tcl"),
        (".xsctcmdhistory", "tcl"),
        (".xsdbcmdhistory", "tcl"),
        ("texmf.cnf", "texmf"),
        ("COPYING", "text"),
        // TODO: could be haredoc
        ("README", "text"),
        ("LICENSE", "text"),
        ("AUTHORS", "text"),
        ("tfrc", "tf"),
        (".tfrc", "tf"),
        ("tidy.conf", "tidy"),
        ("tidyrc", "tidy"),
        (".tidyrc", "tidy"),
        (".tmux.conf", "tmux"),
        ("Cargo.lock", "toml"),
        ("/.cargo/config", "toml"),
        ("/.cargo/credentials", "toml"),
        ("Pipfile", "toml"),
        ("Gopkg.lock", "toml"),
        ("uv.lock", "toml"),
        (".black", "toml"),
        // TODO: could be toml
        ("black", ""),
        ("trustees.conf", "trustees"),
        (".ts_node_repl_history", "typescript"),
        ("/etc/udev/udev.conf", "udevconf"),
        ("/etc/updatedb.conf", "updatedb"),
        ("fdrupstream.log", "upstreamlog"),
        ("vgrindefs", "vgrindefs"),
        (".exrc", "vim"),
        ("_exrc", "vim"),
        (".netrwhist", "vim"),
        ("_viminfo", "viminfo"),
        (".viminfo", "viminfo"),
        (".wgetrc", "wget"),
        (".wget2rc", "wget2"),
        ("wgetrc", "wget"),
        ("wget2rc", "wget2"),
        (".wvdialrc", "wvdial"),
        ("wvdial.conf", "wvdial"),
        (".XCompose", "xcompose"),
        ("Compose", "xcompose"),
        (".Xresources", "xdefaults"),
        (".Xpdefaults", "xdefaults"),
        ("xdm-config", "xdefaults"),
        (".Xdefaults", "xdefaults"),
        ("xorg.conf", "xf86conf"),
        ("xorg.conf-4", "xf86conf"),
        ("XF86Config", "xf86conf"),
        ("/etc/xinetd.conf", "xinetd"),
        ("fglrxrc", "xml"),
        ("/etc/blkid.tab", "xml"),
        ("/etc/blkid.tab.old", "xml"),
        ("fonts.conf", "xml"),
        ("Directory.Packages.props", "xml"),
        ("Directory.Build.props", "xml"),
        ("Directory.Build.targets", "xml"),
        (".clangd", "yaml"),
        (".clang-format", "yaml"),
        (".clang-tidy", "yaml"),
        ("pixi.lock", "yaml"),
        ("yarn.lock", "yaml"),
        ("matplotlibrc", "yaml"),
        (".condarc", "yaml"),
        ("condarc", "yaml"),
        ("zathurarc", "zathurarc"),
        ("/etc/zprofile", "zsh"),
        (".zlogin", "zsh"),
        (".zlogout", "zsh"),
        (".zshrc", "zsh"),
        (".zprofile", "zsh"),
        (".zcompdump", "zsh"),
        (".zsh_history", "zsh"),
        (".zshenv", "zsh"),
        (".zfbfmarks", "zsh"),
    ])
});

static PATTERNS: LazyLock<(RegexSet, Vec<&str>)> = LazyLock::new(|| {
    let home = var("HOME");
    let xdg_config_home = var("XDG_CONFIG_HOME");
    let gnupghome = var("GNUPGHOME");

    let maps = [
        ("/debian/changelog$", "debchangelog"),
        ("/debian/control$", "debcontrol"),
        ("/debian/copyright$", "debcopyright"),
        // TODO: nil-ing i guess?
        ("/debian/patches/", "dep3patch"),
        (r"/etc/a2ps\.cfg$", "a2ps"),
        (r"/etc/a2ps/.*\.cfg$", "a2ps"),
        ("/etc/aliases$", "mailaliases"),
        // TODO: whatever the hell starsetf is
        (r"/etc/apache2/conf\..*/", "apache"),
        (r"/etc/apache2/.*\.conf", "apache"),
        (r"/etc/apache2/mods\..*/", "apache"),
        (r"/etc/apache2/sites\..*/.*\.com$", "apache"),
        (r"/etc/apache2/sites\..*/", "apache"),
        (r"/etc/apt/sources\.list$", "debsources"),
        (r"/etc/apt/sources\.list\.d/.*\.list$", "debsources"),
        (r"/etc/apt/sources\.list\.d/.*\.sources$", "deb822sources"),
        (r"/etc/asound\.conf$", "alsaconf"),
        (r"/etc/blkid\.tab$", "xml"),
        (r"/etc/blkid\.tab\.old$", "xml"),
        (r"/etc/cdrdao\.conf$", "cdrdaoconf"),
        // TODO: nil-ing i guess?
        ("/etc/config/", "uci"),
        (r"/etc/conf\.modules$", "modconf"),
        // TODO: whatever the hell starsetf is
        (r"/etc/cron\.d/", "crontab"),
        ("/etc/default/cdrdao$", "cdrdaoconf"),
        ("/etc/defaults/cdrdao$", "cdrdaoconf"),
        ("/etc/DIR_COLORS$", "dircolors"),
        (r"/etc/dnsmasq\.conf$", "dnsmasq"),
        // TODO: whatever the hell starsetf is
        (r"/etc/dnsmasq\.d/", "dnsmasq"),
        ("/etc/gitattributes$", "gitattributes"),
        ("/etc/gitconfig$", "gitconfig"),
        // TODO: whatever the hell starsetf is
        (r"/etc/gitconfig\.d/", "gitconfig"),
        (r"/etc/group\.$", "group"),
        ("/etc/group$", "group"),
        (r"/etc/group\.edit$", "group"),
        (r"/etc/grub\.conf$", "grub"),
        (r"/etc/gshadow\.$", "group"),
        ("/etc/gshadow$", "group"),
        (r"/etc/gshadow\.edit$", "group"),
        (r"/etc/host\.conf$", "hostconf"),
        // TODO: whatever the hell starsetf is
        (r"/etc/hostname\.", "config"),
        (r"/etc/hosts\.allow$", "hostsaccess"),
        (r"/etc/hosts\.deny$", "hostsaccess"),
        (r"/etc/httpd/.*\.conf$", "apache"),
        (r"/etc/httpd/conf\.d/.*\.conf", "apache"),
        (r"/etc/httpd/conf\..*/", "apache"),
        (r"/etc/httpd/mods\..*/", "apache"),
        (r"/etc/httpd/sites\..*/", "apache"),
        (r"/etc/init/.*\.conf$", "upstart"),
        (r"/etc/initng/.*/.*\.i$", "initng"),
        (r"/etc/init/.*\.override$", "upstart"),
        (r"/etc/libao\.conf$", "libao"),
        ("/etc/limits$", "limits"),
        (r"/etc/.*limits\.conf$", "limits"),
        (r"/etc/.*limits\.d/.*\.conf$", "limits"),
        // TODO: whatever the hell starsetf is
        (r"/etc/logcheck/.*\.d.*/", "logcheck"),
        (r"/etc/login\.access$", "loginaccess"),
        (r"/etc/login\.defs$", "logindefs"),
        ("/etc/mail/aliases$", "mailaliases"),
        (r"/etc/man\.conf$", "manconf"),
        // TODO: whatever the hell starsetf is
        (r"/etc/modprobe\.", "modconf"),
        ("/etc/modules$", "modconf"),
        (r"/etc/modules\.conf$", "modconf"),
        // TODO: nil-ing i guess?
        ("/etc/modutils/", "modconf"),
        // TODO: whatever the hell starsetf is
        (r"/etc/Muttrc\.d/", "muttrc"),
        ("/etc/nanorc$", "nanorc"),
        ("/etc/nginx/", "nginx"),
        (r"/etc/pam\.conf$", "pamconf"),
        // TODO: whatever the hell starsetf is
        (r"/etc/pam\.d/", "pamconf"),
        (r"/etc/passwd\.$", "passwd"),
        ("/etc/passwd$", "passwd"),
        (r"/etc/passwd\.edit$", "passwd"),
        ("/etc/pinforc$", "pinfo"),
        ("/etc/profile$", "bash"),
        // TODO: whatever the hell starsetf is
        (r"/etc/proftpd/.*\.conf", "apachestyle"),
        (r"/etc/proftpd/conf\..*/", "apachestyle"),
        ("/etc/protocols$", "protocols"),
        (r"/etc/sensors3\.conf$", "sensors"),
        (r"/etc/sensors\.conf$", "sensors"),
        // TODO: whatever the hell starsetf is
        (r"/etc/sensors\.d/[^.]", "sensors"),
        (r"/etc/serial\.conf$", "setserial"),
        ("/etc/services$", "services"),
        (r"/etc/shadow\.$", "passwd"),
        ("/etc/shadow$", "passwd"),
        (r"/etc/shadow\.edit$", "passwd"),
        (r"/etc/slp\.conf$", "slpconf"),
        (r"/etc/slp\.reg$", "slpreg"),
        (r"/etc/slp\.spi$", "slpspi"),
        (r"/etc/ssh/ssh_config\.d/.*\.conf$", "sshconfig"),
        (r"/etc/ssh/sshd_config\.d/.*\.conf$", "sshdconfig"),
        ("/etc/sudoers$", "sudoers"),
        // TODO: whatever the hell starsetf is
        (r"/etc/sudoers\.d/", "sudoers"),
        (r"/etc/sysctl\.conf$", "sysctl"),
        (r"/etc/sysctl\.d/.*\.conf$", "sysctl"),
        (r"/etc/systemd/.*\.conf\.d/.*\.conf$", "systemd"),
        (r"/etc/systemd/system/.*\.d/.*\.conf$", "systemd"),
        (r"/etc/systemd/system/.*\.d/\.#", "systemd"),
        (r"/etc/systemd/system/\.#", "systemd"),
        (r"/etc/translate\.shell$", "clojure"),
        (r"/etc/udev/cdsymlinks\.conf$", "sh"),
        (r"/etc/udev/permissions\.d/.*\.permissions$", "udevperm"),
        (r"/etc/udev/udev\.conf$", "udevconf"),
        (r"/etc/updatedb\.conf$", "updatedb"),
        (r"/etc/xdg/menus/.*\.menu$", "xml"),
        (r"/etc/xinetd\.conf$", "xinetd"),
        // TODO: whatever the hell starsetf is
        (r"/etc/xinetd\.d/", "xinetd"),
        (r"/etc/yum\.conf$", "dosini"),
        // TODO: whatever the hell starsetf is
        (r"/etc/yum\.repos\.d/", "dosini"),
        ("/etc/zprofile$", "zsh"),
        (r"/log/auth\.crit$", "messages"),
        (r"/log/auth\.err$", "messages"),
        (r"/log/auth\.info$", "messages"),
        (r"/log/auth\.log$", "messages"),
        (r"/log/auth\.notice$", "messages"),
        (r"/log/auth\.warn$", "messages"),
        ("/log/auth$", "messages"),
        (r"/log/cron\.crit$", "messages"),
        (r"/log/cron\.err$", "messages"),
        (r"/log/cron\.info$", "messages"),
        (r"/log/cron\.log$", "messages"),
        (r"/log/cron\.notice$", "messages"),
        (r"/log/cron\.warn$", "messages"),
        ("/log/cron$", "messages"),
        (r"/log/daemon\.crit$", "messages"),
        (r"/log/daemon\.err$", "messages"),
        (r"/log/daemon\.info$", "messages"),
        (r"/log/daemon\.log$", "messages"),
        (r"/log/daemon\.notice$", "messages"),
        (r"/log/daemon\.warn$", "messages"),
        ("/log/daemon$", "messages"),
        (r"/log/debug\.crit$", "messages"),
        (r"/log/debug\.err$", "messages"),
        (r"/log/debug\.info$", "messages"),
        (r"/log/debug\.log$", "messages"),
        (r"/log/debug\.notice$", "messages"),
        (r"/log/debug\.warn$", "messages"),
        ("/log/debug$", "messages"),
        (r"/log/kern\.crit$", "messages"),
        (r"/log/kern\.err$", "messages"),
        (r"/log/kern\.info$", "messages"),
        (r"/log/kern\.log$", "messages"),
        (r"/log/kern\.notice$", "messages"),
        (r"/log/kern\.warn$", "messages"),
        ("/log/kern$", "messages"),
        (r"/log/lpr\.crit$", "messages"),
        (r"/log/lpr\.err$", "messages"),
        (r"/log/lpr\.info$", "messages"),
        (r"/log/lpr\.log$", "messages"),
        (r"/log/lpr\.notice$", "messages"),
        (r"/log/lpr\.warn$", "messages"),
        ("/log/lpr$", "messages"),
        (r"/log/mail\.crit$", "messages"),
        (r"/log/mail\.err$", "messages"),
        (r"/log/mail\.info$", "messages"),
        (r"/log/mail\.log$", "messages"),
        (r"/log/mail\.notice$", "messages"),
        (r"/log/mail\.warn$", "messages"),
        ("/log/mail$", "messages"),
        (r"/log/messages\.crit$", "messages"),
        (r"/log/messages\.err$", "messages"),
        (r"/log/messages\.info$", "messages"),
        (r"/log/messages\.log$", "messages"),
        (r"/log/messages\.notice$", "messages"),
        (r"/log/messages\.warn$", "messages"),
        ("/log/messages$", "messages"),
        (r"/log/news/news\.crit$", "messages"),
        (r"/log/news/news\.err$", "messages"),
        (r"/log/news/news\.info$", "messages"),
        (r"/log/news/news\.log$", "messages"),
        (r"/log/news/news\.notice$", "messages"),
        (r"/log/news/news\.warn$", "messages"),
        ("/log/news/news$", "messages"),
        (r"/log/syslog\.crit$", "messages"),
        (r"/log/syslog\.err$", "messages"),
        (r"/log/syslog\.info$", "messages"),
        (r"/log/syslog\.log$", "messages"),
        (r"/log/syslog\.notice$", "messages"),
        (r"/log/syslog\.warn$", "messages"),
        ("/log/syslog$", "messages"),
        (r"/log/user\.crit$", "messages"),
        (r"/log/user\.err$", "messages"),
        (r"/log/user\.info$", "messages"),
        (r"/log/user\.log$", "messages"),
        (r"/log/user\.notice$", "messages"),
        (r"/log/user\.warn$", "messages"),
        ("/log/user$", "messages"),
        (r"/\.config/systemd/user/\.#", "systemd"),
        (r"/\.config/systemd/user/.*\.d/\.#", "systemd"),
        (r"/\.config/systemd/user/.*\.d/.*\.conf$", "systemd"),
        (r"/systemd/.*\.automount$", "systemd"),
        (r"/systemd/.*\.dnssd$", "systemd"),
        (r"/systemd/.*\.link$", "systemd"),
        (r"/systemd/.*\.mount$", "systemd"),
        (r"/systemd/.*\.netdev$", "systemd"),
        (r"/systemd/.*\.network$", "systemd"),
        (r"/systemd/.*\.nspawn$", "systemd"),
        (r"/systemd/.*\.path$", "systemd"),
        (r"/systemd/.*\.service$", "systemd"),
        (r"/systemd/.*\.slice$", "systemd"),
        (r"/systemd/.*\.socket$", "systemd"),
        (r"/systemd/.*\.swap$", "systemd"),
        (r"/systemd/.*\.target$", "systemd"),
        (r"/systemd/.*\.timer$", "systemd"),
        (r"/usr/share/alsa/alsa\.conf$", "alsaconf"),
        (r"/usr/.*/gnupg/options\.skel$", "gpg"),
        (r"/usr/share/upstart/.*\.conf$", "upstart"),
        (r"/usr/share/upstart/.*\.override$", "upstart"),
        (r"/var/backups/group\.bak$", "group"),
        (r"/var/backups/gshadow\.bak$", "group"),
        (r"/var/backups/passwd\.bak$", "passwd"),
        (r"/var/backups/shadow\.bak$", "passwd"),
        (r"/\.aptitude/config$", "aptconf"),
        (r"/build/conf/.*\.conf$", "bitbake"),
        (r"/meta\..*/conf/.*\.conf$", "bitbake"),
        (r"/meta/conf/.*\.conf$", "bitbake"),
        (r"/project\.spec/configs/.*\.conf$", "bitbake"),
        (r"/\.cabal/config$", "cabalconfig"),
        ("/cabal/config$", "cabalconfig"),
        (r"/\.aws/config$", "confini"),
        ("/bpython/config$", "dosini"),
        ("/flatpak/repo/config$", "dosini"),
        ("/mypy/config$", "dosini"),
        (fmt!(r"^{home}/\.config/notmuch/.*/config$"), "dosini"),
        (fmt!("^{xdg_config_home}/notmuch/.*/config$"), "dosini"),
        (fmt!("^{xdg_config_home}/git/config$"), "gitconfig"),
        (r"\.git/config\.worktree$", "gitconfig"),
        (r"\.git/config$", "gitconfig"),
        (r"\.git/modules/.*/config$", "gitconfig"),
        (r"\.git/modules/config$", "gitconfig"),
        (r"\.git/worktrees/.*/config\.worktree$", "gitconfig"),
        (r"/\.config/git/config$", "gitconfig"),
        // TODO: whatever the hell starsetf is
        (r"/gitolite\.admin/conf/", "gitolite"),
        (r"/\.i3/config$", "i3config"),
        ("/i3/config$", "i3config"),
        (r"/\.mplayer/config$", "mplayerconf"),
        ("/supertux2/config$", "scheme"),
        (r"/neofetch/config\.conf$", "sh"),
        (r"/\.ssh/config$", "sshconfig"),
        (r"/\.sway/config$", "swayconfig"),
        ("/sway/config$", "swayconfig"),
        (r"/\.cargo/config$", "toml"),
        (r"/\.bundle/config$", "yaml"),
        (r"/\.kube/config$", "yaml"),
        (r"/\.aws/credentials$", "confini"),
        // TODO: whatever the hell starsetf is
        (r"/\.gitconfig\.d/", "gitconfig"),
        (r"/\.gnupg/gpg\.conf$", "gpg"),
        (r"/\.gnupg/options$", "gpg"),
        (r"/\.icewm/menu$", "icemenu"),
        (r"/\.libao$", "libao"),
        (r"/\.pinforc$", "pinfo"),
        (r"/\.cargo/credentials$", "toml"),
        (r"/\.init/.*\.override$", "upstart"),
        // TODO: whatever the hell starsetf is
        (r"/\.calendar/", "calendar"),
        (r"/share/calendar/.*/calendar\.", "calendar"),
        (r"/share/calendar/calendar\.", "calendar"),
        (r"/\.?cmus/.*\.theme$", "cmusrc"),
        (r"/\.?cmus/rc$", "cmusrc"),
        (r"/\.cmus/autosave$", "cmusrc"),
        (r"/\.cmus/command\.history$", "cmusrc"),
        // TODO: nil-ing i guess?
        (r"\.git/", "git"),
        (fmt!("^{xdg_config_home}/git/attributes$"), "gitattributes"),
        (r"\.git/info/attributes$", "gitattributes"),
        (r"/\.config/git/attributes$", "gitattributes"),
        (fmt!("^{xdg_config_home}/git/ignore$"), "gitignore"),
        (r"\.git/info/exclude$", "gitignore"),
        (r"/\.config/git/ignore$", "gitignore"),
        (r"enlightenment/.*\.cfg$", "c"),
        (r"Eterm/.*\.cfg$", "eterm"),
        (r"baseq[2-3/.*\.cfg$]", "quake"),
        (r"id1/.*\.cfg$", "quake"),
        (r"quake[1-3/.*\.cfg$]", "quake"),
        (r"/tex/latex/.*\.cfg$", "tex"),
        // TODO: whatever the hell starsetf is
        (r"^proftpd\.conf", "apachestyle"),
        (r"^access\.conf", "apache"),
        (r"^apache\.conf", "apache"),
        (r"^apache2\.conf", "apache"),
        (r"^httpd\.conf", "apache"),
        (r"^httpd\..*\.conf", "apache"),
        (r"^proxy\.html\.conf", "apache"),
        (r"^srm\.conf", "apache"),
        // TODO: whatever the hell starsetf is
        (r"asterisk/.*\.conf", "asterisk"),
        // TODO: whatever the hell starsetf is
        (r"asterisk.*/.*voicemail\.conf", "asteriskvm"),
        (r"^dictd.*\.conf$", "dictdconf"),
        (r"/\.?gnuradio/.*\.conf$", "confini"),
        (r"/gnuradio/conf\.d/.*\.conf$", "confini"),
        (r"/lxqt/.*\.conf$", "dosini"),
        (r"/screengrab/.*\.conf$", "dosini"),
        (r"/\.config/fd/ignore$", "gitignore"),
        (fmt!(r"^{gnupghome}/gpg\.conf$"), "gpg"),
        (r"/boot/grub/grub\.conf$", "grub"),
        (r"/hypr/.*\.conf$", "hyprlang"),
        // TODO: whatever the hell starsetf is
        (r"^lilo\.conf", "lilo"),
        (r"^named.*\.conf$", "named"),
        (r"^rndc.*\.conf$", "named"),
        (r"/openvpn/.*/.*\.conf$", "openvpn"),
        (r"/pipewire/.*\.conf$", "spajson"),
        (r"/wireplumber/.*\.conf$", "spajson"),
        (r"/\.ssh/.*\.conf$", "sshconfig"),
        (r"^\.?tmux.*\.conf$", "tmux"),
        (r"^\.?tmux.*\.conf", "tmux"),
        (r"/containers/containers\.conf$", "toml"),
        (r"/containers/containers\.conf\.d/.*\.conf$", "toml"),
        (r"/containers/containers\.conf\.modules/.*\.conf$", "toml"),
        (r"/containers/registries\.conf$", "toml"),
        (r"/containers/registries\.conf\.d/.*\.conf$", "toml"),
        (r"/containers/storage\.conf$", "toml"),
        (r"/\.config/upstart/.*\.conf$", "upstart"),
        (r"/\.config/upstart/.*\.override$", "upstart"),
        (r"/\.init/.*\.conf$", "upstart"),
        (r"/xorg\.conf\.d/.*\.conf$", "xf86conf"),
        (r"\.\.sst\.meta$", "sisu"),
        (r"\._sst\.meta$", "sisu"),
        (r"\.sst\.meta$", "sisu"),
        // TODO: Whatever the hell starsetf is
        (r"^Containerfile\.", "dockerfile"),
        (r"^Dockerfile\.", "dockerfile"),
        ("[mM]akefile$", "make"),
        // TODO: Whatever the hell starsetf is
        ("^[mM]akefile", "make"),
        // TODO: Whatever the hell starsetf is
        ("^[rR]akefile", "ruby"),
        (r"^\.profile", "bash"),
        // TODO: Whatever the hell starsetf is
        (r"/\.fvwm/", "fvwm"),
        ("fvwmrc", "fvwm"),
        (r"fvwm95.*\.hook$", "fvwm"),
        // TODO: Could be fvwm2m4
        ("fvwm2rc", "fvwm"),
        (r"/nginx/.*\.conf$", "nginx"),
        ("/usr/local/nginx/conf/", "nginx"),
        (r"nginx\.conf$", "nginx"),
        (r"^nginx.*\.conf$", "nginx"),
        (r"\.requirements\.txt$", "requirements"),
        (r"^requirements/.*\.txt$", "requirements"),
        (r"^requires/.*\.txt$", "requirements"),
        ("s6.*/down$", "execline"),
        ("s6.*/finish$", "execline"),
        ("s6.*/run$", "execline"),
        ("s6.*/up$", "execline"),
        (r"^s6\.", "execline"),
        (r"^mutt\..*\.\.+$", "mail"),
        (r"^mutt[\._-]{6}$", "mail"),
        (r"^muttng\..*\.\.+$", "mail"),
        (r"^neomutt\..*\.\.+$", "mail"),
        (r"^neomutt[\._-]$", "mail"),
        // TODO: Whatever the hell starsetf is
        (r"^\.?muttngrc", "muttrc"),
        (r"^\.?muttrc", "muttrc"),
        (r"/\.mutt/muttrc", "muttrc"),
        (r"/\.muttng/muttngrc", "muttrc"),
        (r"/\.muttng/muttrc", "muttrc"),
        ("^Muttngrc", "muttrc"),
        ("^Muttrc", "muttrc"),
        // TODO: Whatever the hell starsetf is
        (r"^\.?neomuttrc", "neomuttrc"),
        (r"/\.neomutt/neomuttrc", "neomuttrc"),
        ("^Neomuttrc", "neomuttrc"),
        (r"\.neomuttdebug", "neomuttlog"),
        // TODO: Whatever the hell starsetf is
        (r"/\.?xkb/compat/", "xkb"),
        (r"/\.?xkb/geometry/", "xkb"),
        (r"/\.?xkb/keycodes/", "xkb"),
        (r"/\.?xkb/symbols/", "xkb"),
        (r"/\.?xkb/types/", "xkb"),
        (r"/m17n/.*\.ali$", "m17ndb"),
        (r"/m17n/.*\.cs$", "m17ndb"),
        (r"/m17n/.*\.dir$", "m17ndb"),
        (r"/m17n/.*\.flt$", "m17ndb"),
        (r"/m17n/.*\.fst$", "m17ndb"),
        (r"/m17n/.*\.lnm$", "m17ndb"),
        (r"/m17n/.*\.mic$", "m17ndb"),
        (r"/m17n/.*\.mim$", "m17ndb"),
        (r"/m17n/.*\.tbl$", "m17ndb"),
        (r"/\.m17n\.d/.*\.ali$", "m17ndb"),
        (r"/\.m17n\.d/.*\.cs$", "m17ndb"),
        (r"/\.m17n\.d/.*\.dir$", "m17ndb"),
        (r"/\.m17n\.d/.*\.flt$", "m17ndb"),
        (r"/\.m17n\.d/.*\.fst$", "m17ndb"),
        (r"/\.m17n\.d/.*\.lnm$", "m17ndb"),
        (r"/\.m17n\.d/.*\.mic$", "m17ndb"),
        (r"/\.m17n\.d/.*\.mim$", "m17ndb"),
        (r"/\.m17n\.d/.*\.tbl$", "m17ndb"),
        (r"/m17n\.db/.*\.ali$", "m17ndb"),
        (r"/m17n\.db/.*\.cs$", "m17ndb"),
        (r"/m17n\.db/.*\.dir$", "m17ndb"),
        (r"/m17n\.db/.*\.flt$", "m17ndb"),
        (r"/m17n\.db/.*\.fst$", "m17ndb"),
        (r"/m17n\.db/.*\.lnm$", "m17ndb"),
        (r"/m17n\.db/.*\.mic$", "m17ndb"),
        (r"/m17n\.db/.*\.mim$", "m17ndb"),
        (r"/m17n\.db/.*\.tbl$", "m17ndb"),
        (r"^\.cshrc", "csh"),
        (r"^\.login", "csh"),
        (r"^\.notmuch\.config\.", "dosini"),
        (r"^\.gitsendemail\.msg\.......$", "gitsendemail"),
        (r"^\.kshrc", "ksh"),
        (r"^\.article\.\.+$", "mail"),
        (r"^\.letter\.\.+$", "mail"),
        (r"^\.reminders", "remind"),
        (r"^\.tcshrc", "tcsh"),
        (r"^\.zcompdump", "zsh"),
        (r"\.csproj\.user$", "xml"),
        (r"\.fsproj\.user$", "xml"),
        (r"\.vbproj\.user$", "xml"),
        (r"^bash\.fc[\-\.]", "bash"),
        (r"/bind/db\.", "bindzone"),
        (r"/named/db\.", "bindzone"),
        (r"\.blade\.php$", "blade"),
        (r"^bzr_log\.", "bzr"),
        // TODO: Whatever the hell starsetf is
        (r"^cabal\.project\.", "cabalproject"),
        (r"^sgml\.catalog", "catalog"),
        ("hgrc$", "cfg"),
        // TODO: Could be debchangelog
        ("^[cC]hange[lL]og", "changelog"),
        (r"\.\.ch$", "chill"),
        (r"\.cmake\.in$", "cmake"),
        // TODO: Whatever the hell starsetf is
        (r"^crontab\.", "crontab"),
        (r"^cvs\.+$", "cvs"),
        ("/DEBIAN/control$", "debcontrol"),
        (r"^php\.ini\.", "dosini"),
        (r"^php\.fpm\.conf", "dosini"),
        (r"^www\.conf", "dosini"),
        // TODO: Whatever the hell starsetf is
        (r"^drac\.", "dracula"),
        (r"/dtrace/.*\.d$", "dtrace"),
        ("esmtprc$", "esmtprc"),
        (r"/0\.orig/", "foam"),
        ("/0/", "foam"),
        ("/constant/g$", "foam"),
        (r"Transport\.", "foam"),
        (r"^[a-zA-Z0-9].*Dict\.", "foam"),
        ("^[a-zA-Z0-9].*Dict$", "foam"),
        (r"^[a-zA-Z].*Properties\.", "foam"),
        ("^[a-zA-Z].*Properties$", "foam"),
        // TODO: Whatever the hell starsetf is
        ("/tmp/lltmp", "gedcom"),
        ("^gkrellmrc_.$", "gkrellmrc"),
        (fmt!("^{gnupghome}/options$"), "gpg"),
        (r"/boot/grub/menu\.lst$", "grub"),
        // TODO: Whatever the hell starsetf is
        (r"^\.?gtkrc", "gtkrc"),
        // (r"/doc/.*\.txt$", function(_, bufnr))
        //   local line, M._getline(bufnr, -1)
        //   if
        //     M._findany(line, {
        //       (r"^vim:ft=help[:\.]"),
        //       ("^vim:ft=help$"),
        //       (r"^vim:filetype=help[:\.]"),
        //       ("^vim:filetype=help$"),
        //       (r"^vim:.*[:\.]ft=help[:\.]"),
        //       (r"^vim:.*[:\.]ft=help$"),
        //       (r"^vim:.*[:\.]filetype=help[:\.]"),
        //       (r"^vim:.*[:\.]filetype=help$"),
        //       (r"\.vim:ft=help[:\.]"),
        //       (r"\.vim:ft=help$"),
        //       (r"\.vim:filetype=help[:\.]"),
        //       (r"\.vim:filetype=help$"),
        //       (r"\.vim:.*[:\.]ft=help[:\.]"),
        //       (r"\.vim:.*[:\.]ft=help$"),
        //       (r"\.vim:.*[:\.]filetype=help[:\.]"),
        //       (r"\.vim:.*[:\.]filetype=help$"),
        //     })
        //   then
        //     return "help"
        //   end
        // end,
        (r"^hg\.editor\..*\.txt$", "hgcommit"),
        (r"\.html\.m4$", "htmlm4"),
        // TODO: Whatever the hell starsetf is
        (r"^JAM.*\.", "jam"),
        (r"^Prl.*\.", "jam"),
        (fmt!(r"^{home}/.*/Code/User/.*\.json$"), "jsonc"),
        (fmt!(r"^{home}/.*/VSCodium/User/.*\.json$"), "jsonc"),
        (r"\.properties_..$", "jproperties"),
        (r"\.properties_.._..$", "jproperties"),
        // TODO: Whatever the hell starsetf is
        (r"\.properties_.._.._", "jproperties"),
        (r"^org\.eclipse\..*\.prefs$", "jproperties"),
        (r"^[jt]sconfig.*\.json$", "jsonc"),
        // TODO: Whatever the hell starsetf is
        (r"^Config\.in\.", "kconfig"),
        (r"^Kconfig\.", "kconfig"),
        ("/ldscripts/", "ld"),
        ("lftp/rc$", "lftp"),
        (r"/LiteStep/.*/.*\.rc$", "litestep"),
        (r"^/tmp/SLRN[0-9A-Z\.]+$", "mail"),
        (r"^ae\.+\.txt$", "mail"),
        (r"^pico\.\.+$", "mail"),
        // TODO: Whatever the hell starsetf is
        (r"^reportbug\.", "mail"),
        (r"^snd\.\.+$", "mail"),
        (r"^rndc.*\.key$", "named"),
        // TODO: Whatever the hell starsetf is
        (r"^tmac\.", "nroff"),
        (r"\.ml\.cppo$", "ocaml"),
        (r"\.mli\.cppo$", "ocaml"),
        ("/octave/history$", "octave"),
        (r"\.opam\.locked$", "opam"),
        (r"\.opam\.template$", "opam"),
        (r"^pacman\.log", "pacmanlog"),
        // ("printcap", starsetf(function(path, bufnr))
        //   return require("vim.filetype.detect").printcap("print")
        // end),
        (r"/queries/.*\.scm$", "query"),
        (",v$", "rcs"),
        (r"^svn\.commit.*\.tmp$", "svn"),
        (r"\.swift\.gyb$", "swiftgyb"),
        // ("termcap", starsetf(function(path, bufnr))
        //   return require("vim.filetype.detect").printcap("term")
        // end),
        (r"\.t\.html$", "tilde"),
        // TODO: Whatever the hell starsetf is
        (r"\.vhdl_[0-9]", "vhdl"),
        // TODO: Whatever the hell starsetf is
        ("vimrc", "vim"),
        // TODO: Whatever the hell starsetf is
        ("/Xresources/", "xdefaults"),
        (r"/app\.defaults/", "xdefaults"),
        ("^Xresources", "xdefaults"),
        (r"^XF86Config\.4", "xf86conf"),
        ("^XF86Config", "xf86conf"),
        ("Xmodmap$", "xmodmap"),
        // TODO: Whatever the hell starsetf is
        ("xmodmap", "xmodmap"),
        // TODO: Whatever the hell starsetf is
        (r"^\.?zlog", "zsh"),
        (r"^\.?zsh", "zsh"),
        // ("~$", function(path, bufnr))
        //   local short, path:gsub("~+$", "", 1)
        //   if path ~= short and short ~= "" then
        //     return M.match({ buf, bufnr, filename, fn.fnameescape(short) })
        //   end
        // end,
    ];

    (
        RegexSet::new(maps.iter().map(|(pat, _)| *pat)).unwrap(),
        Vec::from_iter(maps.iter().map(|(_, lang)| *lang)),
    )
});

fn var(str: &str) -> String {
    std::env::var(str).unwrap_or_default()
}
