Replaces the piece of crap xdg-open. Written in V.

Depends on the Perl package File-MimeInfo, (on OpenBSD install with `pkg_add p5-File-MimeInfo`)
Config file ~/.config/opener/mime.conf has one mime type per line, in the form
`mimetype`[space]`program to use`
e.g.
application/pdf mupdf
text/plain lite-xl
video/x-matroska mpv

Then configure your file manager to use it, eg:
Using nnn: `export NNN_OPENER=mime-opener.tcl` in .profile
Using lf: `map o &mime-opener.tcl $f` in .config/lf/lfrc
Or, rename it to xdg-open and put in your $PATH ahead of
the shit official version.




  

import os                                                    

fn main() {
    mime_list := get_mime_list()
    mut file_to_launch := os.args[1]
    file_to_launch = file_to_launch.replace(' ','\\ ')
    prog_to_use := get_prog_to_use(file_to_launch, mime_list)
    os.execute('${prog_to_use} ${file_to_launch}')
}

fn get_mime_list() []string {
    filename := '~/.config/opener/mime.conf'
    d := os.read_lines(filename) or {
        panic('error reading file $filename')
    }
    return(d)
}

fn get_prog_to_use (a string, b []string) string {
    mime_to_use := os.execute('mimetype -b ${a}')
    mut query := mime_to_use.output
    query = query.replace('\n','')
    mut c := ""
    for entry in b {
        if entry.contains(query) {
            c = entry
            d := c.split(' ')
            c = d[1]
        } 
    }
    return(c)
}