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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
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 Arg
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
-- Handler of an uri glob. Mime maps the uri to a file handler. Transparent is a command which, when run, returns a mimetype of the file.
UriGlobHandler =
< Transparent : Command | Mime : Mime >
let UriMimeGlob = { desc : Text, glob : List Text, handler : UriGlobHandler }
let Special =
{ open-in-editor : Command
, open-in-browser : Command
, fetch-http-url-mime : Command
, compose-mail-to : Command
, exec-in-terminal-emulator : ∀(args : Command) → Command
, dmenu-list-binaries-and-exec : Command
}
let uriMimeGlobs
: Special → List UriMimeGlob
= λ(special : Special) →
[ { desc = "http link"
, glob = [ "http://*", "https://*" ]
, handler =
let TODO = UriGlobHandler.Transparent special.fetch-http-url-mime
in UriGlobHandler.Mime mime.text.html
}
, { glob = [ "mailto:*" ]
, desc = "mail address"
, handler = UriGlobHandler.Mime mime.mail-address
}
, { glob = [ "magnet:*" ]
, desc = "bittorrent magnet link"
, handler = UriGlobHandler.Mime mime.torrent
}
, { desc = "irc channel"
, glob = [ "irc:*" ]
, handler = UriGlobHandler.Mime mime.irc
}
, { desc = "local file"
, glob = [ "file://*" ]
, handler = UriGlobHandler.Mime mime.file
}
]
let MimeMatch = { match : Mime, cmd : Command }
let mimeMatcher =
λ(pkgs : { package : Text, binary : Text } → Executable) →
λ(special : Special) →
let pkgSame =
λ(packageAndBinaryName : Text) →
pkgs
{ package = packageAndBinaryName
, binary = packageAndBinaryName
}
let wrapCommand =
λ(wrapper : Command) →
λ(cmd : Command) →
{ exe = wrapper.exe
, args =
λ(template : Arg) →
wrapper.args template
# [ Arg.String cmd.exe ]
# cmd.args template
}
let oneArg =
λ(exe : Executable) → { exe, args = λ(file : Arg) → [ file ] }
let m = λ(match : Mime) → λ(cmd : Command) → { match, 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 "imv") }
, { match = mime.pdf, cmd = oneArg (pkgSame "zathura") }
, { match = mime.pgp-key
, cmd =
{ exe = pkgs { package = "gnupg", binary = "gpg" }
, args =
λ(file : Arg) →
[ Arg.String "--import"
, Arg.String "--import-options"
, Arg.String "show-only"
, 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
, uriMimeGlobs
, UriMimeGlob
, Executable
, Command
, UriGlobHandler
, MimeMatch
, Special
, Mime
, Arg
}
|