1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
let Mime = List Text
let
-- TODO use library like with shell commands
Executable =
Text
let Arg = < String : Text | Variable : Text >
let CommandTemplate =
λ(templates : Type) → { exe : Executable, args : templates → List Arg }
let Command = CommandTemplate Text
let mime =
{ text =
{ html = [ "text", "html" ]
, xml = [ "text", "xml" ]
, any = [ "text", "*" ]
}
, mail-address = [ "special", "mailaddress" ]
, torrent = [ "application", "x-bittorrent" ]
, irc = [ "x-scheme-handler", "irc" ]
, file = [ "x-scheme-handler", "file" ]
, image =
{ gif = [ "image", "gif" ]
, svg = [ "image", "svg+xml" ]
, any = [ "image", "*" ]
}
, pdf = [ "application", "pdf" ]
, pgp-key = [ "application", "pgp-keys" ]
, directory = [ "inode", "directory" ]
, any = [ "*" ]
}
let renderMime = λ(m : Mime) → 32
let uriMimeGlobs =
[ { desc = "http link"
, glob = [ "http://*", "https://*" ]
, mime = mime.text.html
}
, { glob = [ "mailto:*" ]
, desc = "mail address"
, mime = mime.mail-address
}
, { glob = [ "magnet:*" ]
, desc = "bittorrent magnet link"
, mime = mime.torrent
}
, { desc = "irc channel", glob = [ "irc:*" ], mime = mime.irc }
, { desc = "local file", glob = [ "file://*" ], mime = mime.file }
]
let MimeMatch = { match : Mime, cmd : Command }
let Special =
{ open-in-editor : Command
, open-in-browser : Command
, compose-mail-to : Command
, exec-in-terminal-emulator : ∀(args : Command) → Command
, dmenu-list-binaries-and-exec : Command
}
let mimeMatcher =
λ(pkgs : { package : Text, binary : Text } → Executable)
→ λ(special : Special)
→ let pkgSame =
λ(packageAndBinaryName : Text)
→ pkgs
{ package = packageAndBinaryName
, binary = packageAndBinaryName
}
let oneArg =
λ(exe : Executable)
→ { exe = exe, args = λ(file : Text) → [ Arg.Variable file ] }
let m =
λ(match : Mime) → λ(cmd : Command) → { match = match, cmd = cmd }
in [ { match = mime.mail-address, cmd = special.compose-mail-to }
, { match = mime.text.html, cmd = special.open-in-browser }
, { match = mime.text.xml, cmd = special.open-in-browser }
, { match = mime.text.any, cmd = special.open-in-editor }
, { match = mime.image.gif, cmd = special.open-in-browser }
, { match = mime.image.svg, cmd = oneArg (pkgSame "inkscape") }
, { match = mime.image.any, cmd = oneArg (pkgSame "feh") }
, { match = mime.pdf, cmd = oneArg (pkgSame "zathura") }
, { match = mime.pgp-key
, cmd =
{ exe = pkgs { package = "gnupg", binary = "gpg" }
, args =
λ(file : Text)
→ [ Arg.String "--import"
, Arg.String "--import-options"
, Arg.String "show-only"
, Arg.Variable file
]
}
}
, { match = mime.directory
, cmd =
special.exec-in-terminal-emulator
(oneArg (pkgSame "ranger"))
}
, { match = mime.any, cmd = special.dmenu-list-binaries-and-exec }
]
: List MimeMatch
in { mimeMatcher = mimeMatcher
, uriMimeGlobs = uriMimeGlobs
, Executable = Executable
, Command = Command
, MimeMatch = MimeMatch
, Special = Special
, Mime = Mime
, Arg = Arg
}
|