diff options
-rw-r--r-- | pkgs/profpatsch/xdg-open/config.dhall | 14 | ||||
-rw-r--r-- | pkgs/profpatsch/xdg-open/types.dhall | 12 | ||||
-rw-r--r-- | pkgs/profpatsch/xdg-open/xdg-open.dhall | 22 |
3 files changed, 29 insertions, 19 deletions
diff --git a/pkgs/profpatsch/xdg-open/config.dhall b/pkgs/profpatsch/xdg-open/config.dhall index 2b1fb686..13810b3a 100644 --- a/pkgs/profpatsch/xdg-open/config.dhall +++ b/pkgs/profpatsch/xdg-open/config.dhall @@ -141,37 +141,37 @@ in λ(pkgs : { package : Text, binary : Text } → Executable) → let TODO = UriGlobHandler.Transparent special.fetch-http-url-mime - in UriGlobHandler.Mime mime.text.html.mime + in UriGlobHandler.Mime mime.text.html } , { desc = "gemini link" , glob = [ "gemini://*" ] , schema-prefix = [ "gemini" ] - , handler = UriGlobHandler.Mime mime.text.gemini.mime + , handler = UriGlobHandler.Mime mime.text.gemini } , { desc = "gemini link" , glob = [ "gopher://*", "gophers://*" ] , schema-prefix = [ "gopher", "gophers" ] - , handler = UriGlobHandler.Mime mime.text.gopher.mime + , handler = UriGlobHandler.Mime mime.text.gopher } , { glob = [ "mailto:*" ] , desc = "mail address" , schema-prefix = [ "mailto" ] - , handler = UriGlobHandler.Mime mime.mail-address.mime + , handler = UriGlobHandler.Mime mime.mail-address } , { glob = [ "magnet:*" ] , desc = "bittorrent magnet link" , schema-prefix = [ "magnet" ] - , handler = UriGlobHandler.Mime mime.torrent.mime + , handler = UriGlobHandler.Mime mime.torrent } , { desc = "irc channel" , glob = [ "irc:*", "ircs:*" ] , schema-prefix = [ "irc", "ircs" ] - , handler = UriGlobHandler.Mime mime.irc.mime + , handler = UriGlobHandler.Mime mime.irc } , { desc = "local file" , glob = [ "file://*" ] , schema-prefix = [ "file" ] - , handler = UriGlobHandler.Mime mime.file.mime + , handler = UriGlobHandler.Mime mime.file } ] diff --git a/pkgs/profpatsch/xdg-open/types.dhall b/pkgs/profpatsch/xdg-open/types.dhall index 72184ad5..b7ae944b 100644 --- a/pkgs/profpatsch/xdg-open/types.dhall +++ b/pkgs/profpatsch/xdg-open/types.dhall @@ -23,9 +23,14 @@ let Special = } let + -- describes the command `cmd` to run for the matched mime type `mime` + MimeMatch = + { mime : Mime, cmd : Command } + +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 > + < Transparent : Command | Mime : MimeMatch > let UriMimeGlob = { desc : Text @@ -36,11 +41,6 @@ let UriMimeGlob = , handler : UriGlobHandler } -let - -- describes the command `cmd` to run for the matched mime type `mime` - MimeMatch = - { mime : Mime, cmd : Command } - in { Mime , Executable , Arg diff --git a/pkgs/profpatsch/xdg-open/xdg-open.dhall b/pkgs/profpatsch/xdg-open/xdg-open.dhall index cd9e8d4c..66ab88a3 100644 --- a/pkgs/profpatsch/xdg-open/xdg-open.dhall +++ b/pkgs/profpatsch/xdg-open/xdg-open.dhall @@ -15,13 +15,17 @@ let types = ./types.dhall let renderMime = Text/concatSep "/" -let shellEscapeCommand = +let + -- Escape the given shell command, at least the String arguments of it. + -- Passes `$file` as variable argument. + -- The final shell command is executed into. + shellEscapeExecCommand = λ(shellEscape : Text → Text) → λ(file : Text) → λ(cmd : types.Command) → Text/concatSep " " - ( [ shellEscape cmd.exe ] + ( [ "exec", shellEscape cmd.exe ] # List/map types.Arg Text @@ -56,7 +60,7 @@ let xdg-open = λ(file2 : Text) → λ(m : types.MimeMatch) → [ "${renderMime m.mime})" - , "${shellEscapeCommand shellEscape2 file2 m.cmd}" + , "${shellEscapeExecCommand shellEscape2 file2 m.cmd}" , ";;" ] @@ -70,12 +74,18 @@ let xdg-open = ( λ(match : Text) → merge { Mime = - λ(mime : types.Mime) → - [ "${match})", "mime=${renderMime mime}", ";;" ] + λ(mime : types.MimeMatch) → + [ "${match})" + , shellEscapeExecCommand + shellEscape2 + file2 + mime.cmd + , ";;" + ] , Transparent = λ(cmd : types.Command) → [ "${match})" - , "mime=\"\$(${shellEscapeCommand + , "mime=\"\$(${shellEscapeExecCommand shellEscape2 file2 cmd})\"" |