about summary refs log tree commit diff
path: root/pkgs/profpatsch/xdg-open/config.dhall
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-05-12 23:05:28 +0200
committerProfpatsch <mail@profpatsch.de>2021-05-12 23:42:13 +0200
commit0d1737778cf81304ec37cea2a1c0e934bb84e601 (patch)
tree85dd4f2de036adb61fcd18ddb66aa2ad08d49c56 /pkgs/profpatsch/xdg-open/config.dhall
parent08bb67826b793e57b8ec17627ba2a52478567700 (diff)
pkgs/profpatsch/xdg-open: prepare for adding firefox handler support
This diff is a bit bad cause of whitespace changes, but effectively
this copies all handlers into the mime handler definitions and
duplicates them for now.

We want to use the same config to generate a firefox mime handler
file.
Diffstat (limited to 'pkgs/profpatsch/xdg-open/config.dhall')
-rw-r--r--pkgs/profpatsch/xdg-open/config.dhall414
1 files changed, 257 insertions, 157 deletions
diff --git a/pkgs/profpatsch/xdg-open/config.dhall b/pkgs/profpatsch/xdg-open/config.dhall
index a3586dda..45ef45d1 100644
--- a/pkgs/profpatsch/xdg-open/config.dhall
+++ b/pkgs/profpatsch/xdg-open/config.dhall
@@ -1,161 +1,261 @@
-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" ]
-        , gemini = [ "text", "gemini" ]
-        , gopher = [ "text", "gopher" ]
-        , 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
-          }
-        , { desc = "gemini link"
-          , glob = [ "gemini://*" ]
-          , handler = UriGlobHandler.Mime mime.text.gemini
-          }
-        , { desc = "gemini link"
-          , glob = [ "gopher://*", "gophers://*" ]
-          , handler = UriGlobHandler.Mime mime.text.gopher
-          }
-        , { 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 types = ./types.dhall
 
-        let wrapCommand =
-              λ(wrapper : Command) →
-              λ(cmd : Command) →
-                { exe = wrapper.exe
-                , args =
-                    λ(template : Arg) →
-                        wrapper.args template
-                      # [ Arg.String cmd.exe ]
-                      # cmd.args template
-                }
+let Executable = types.Executable
+
+let Special = types.Special
+
+let Command = types.Command
+
+let Arg = types.Arg
+
+let Mime = types.Mime
+
+let UriGlobHandler = types.UriGlobHandler
+
+let UriMimeGlob = types.UriMimeGlob
+
+let MimeMatch = types.MimeMatch
+
+in  λ(pkgs : { package : Text, binary : Text } → Executable) →
+    λ(special : Special) →
+      let mime =
+            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
+                -- An executable that takes as its one argument the file to run
+                oneArg =
+                  λ(exe : Executable) → { exe, args = λ(file : Arg) → [ file ] }
 
-        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.gemini, cmd = oneArg (pkgSame "lagrange") }
-              , { match = mime.text.gopher, cmd = oneArg (pkgSame "lagrange") }
-              , { 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
-                        ]
+            in  { text =
+                  { html =
+                    { mime = [ "text", "html" ], cmd = special.compose-mail-to }
+                  , gemini =
+                    { mime = [ "text", "gemini" ]
+                    , cmd = oneArg (pkgSame "lagrange")
+                    }
+                  , gopher =
+                    { mime = [ "text", "gopher" ]
+                    , cmd = oneArg (pkgSame "lagrange")
+                    }
+                  , xml =
+                    { mime = [ "text", "xml" ], cmd = special.open-in-browser }
+                  , any =
+                    { mime = [ "text", "any" ], cmd = special.open-in-editor }
                   }
+                , mail-address =
+                  { mime = [ "special", "mailaddress" ]
+                  , cmd = special.compose-mail-to
+                  }
+                , torrent =
+                  { mime = [ "application", "x-bittorrent" ]
+                  , cmd = special.notify "No xdg-open handler for the torrent"
+                  }
+                , irc =
+                  { mime = [ "x-scheme-handler", "irc" ]
+                  , cmd = special.notify "No xdg-open handler for the irc link"
+                  }
+                , file =
+                  { mime = [ "x-scheme-handler", "file" ]
+                  , cmd =
+                      special.notify
+                        "No xdg-open handler for the x-scheme-handler/file"
+                  }
+                , image =
+                  { gif =
+                    { mime = [ "image", "gif" ], cmd = special.open-in-browser }
+                  , svg =
+                    { mime = [ "image", "svg+xml" ]
+                    , cmd = oneArg (pkgSame "inkscape")
+                    }
+                  , any =
+                    { mime = [ "image", "*" ], cmd = oneArg (pkgSame "imv") }
+                  }
+                , pdf =
+                  { mime = [ "application", "pdf" ]
+                  , cmd = oneArg (pkgSame "zathura")
+                  }
+                , pgp-key =
+                  { mime = [ "application", "pgp-keys" ]
+                  , cmd =
+                    { exe = pkgs { package = "gnupg", binary = "gpg" }
+                    , args =
+                        λ(file : Arg) →
+                          [ Arg.String "--import"
+                          , Arg.String "--import-options"
+                          , Arg.String "show-only"
+                          , file
+                          ]
+                    }
+                  }
+                , directory =
+                  { mime = [ "inode", "directory" ]
+                  , cmd =
+                      special.exec-in-terminal-emulator
+                        (oneArg (pkgSame "ranger"))
+                  }
+                , any =
+                  { mime = [ "*" ], cmd = special.dmenu-list-binaries-and-exec }
                 }
-              , { 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
-    }
+
+      let matchOrder =
+            [ mime.text.html
+            , mime.text.gemini
+            , mime.text.gopher
+            , mime.text.xml
+            , mime.text.any
+            , mime.mail-address
+            , mime.torrent
+            , mime.irc
+            , mime.file
+            , mime.image.gif
+            , mime.image.svg
+            , mime.image.any
+            , mime.pdf
+            , mime.pgp-key
+            , mime.directory
+            , mime.any
+            ]
+
+      let uriMimeGlobs
+          : List UriMimeGlob
+          = [ { desc = "http link"
+              , glob = [ "http://*", "https://*" ]
+              , schema-prefix = [ "http", "https" ]
+              , handler =
+                  let TODO =
+                        UriGlobHandler.Transparent special.fetch-http-url-mime
+
+                  in  UriGlobHandler.Mime mime.text.html.mime
+              }
+            , { desc = "gemini link"
+              , glob = [ "gemini://*" ]
+              , schema-prefix = [ "gemini" ]
+              , handler = UriGlobHandler.Mime mime.text.gemini.mime
+              }
+            , { desc = "gemini link"
+              , glob = [ "gopher://*", "gophers://*" ]
+              , schema-prefix = [ "gopher", "gophers" ]
+              , handler = UriGlobHandler.Mime mime.text.gopher.mime
+              }
+            , { glob = [ "mailto:*" ]
+              , desc = "mail address"
+              , schema-prefix = [ "mailto" ]
+              , handler = UriGlobHandler.Mime mime.mail-address.mime
+              }
+            , { glob = [ "magnet:*" ]
+              , desc = "bittorrent magnet link"
+              , schema-prefix = [ "magnet" ]
+              , handler = UriGlobHandler.Mime mime.torrent.mime
+              }
+            , { desc = "irc channel"
+              , glob = [ "irc:*", "ircs:*" ]
+              , schema-prefix = [ "irc", "ircs" ]
+              , handler = UriGlobHandler.Mime mime.irc.mime
+              }
+            , { desc = "local file"
+              , glob = [ "file://*" ]
+              , schema-prefix = [ "file" ]
+              , handler = UriGlobHandler.Mime mime.file.mime
+              }
+            ]
+
+      let mimeMatcher =
+            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.mime
+                    , cmd = special.compose-mail-to
+                    }
+                  , { match = mime.text.html.mime
+                    , cmd = special.open-in-browser
+                    }
+                  , { match = mime.text.gemini.mime
+                    , cmd = oneArg (pkgSame "lagrange")
+                    }
+                  , { match = mime.text.gopher.mime
+                    , cmd = oneArg (pkgSame "lagrange")
+                    }
+                  , { match = mime.text.xml.mime
+                    , cmd = special.open-in-browser
+                    }
+                  , { match = mime.text.any.mime, cmd = special.open-in-editor }
+                  , { match = mime.image.gif.mime
+                    , cmd = special.open-in-browser
+                    }
+                  , { match = mime.image.svg.mime
+                    , cmd = oneArg (pkgSame "inkscape")
+                    }
+                  , { match = mime.image.any.mime
+                    , cmd = oneArg (pkgSame "imv")
+                    }
+                  , { match = mime.pdf.mime, cmd = oneArg (pkgSame "zathura") }
+                  , { match = mime.pgp-key.mime
+                    , 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.mime
+                    , cmd =
+                        special.exec-in-terminal-emulator
+                          (oneArg (pkgSame "ranger"))
+                    }
+                  , { match = mime.any.mime
+                    , cmd = special.dmenu-list-binaries-and-exec
+                    }
+                  ]
+                : List MimeMatch
+
+      in  { mimeMatcher
+          , uriMimeGlobs
+          , UriMimeGlob
+          , Executable
+          , Command
+          , UriGlobHandler
+          , MimeMatch
+          , Special
+          , Mime
+          , Arg
+          }