about summary refs log tree commit diff
path: root/pkgs/profpatsch/xdg-open/config.dhall
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2020-05-09 21:12:03 +0200
committerProfpatsch <mail@profpatsch.de>2020-05-09 21:13:09 +0200
commit0adf4290a0eaab8b907d34f66c4831c3493b25fb (patch)
treeb8987cbc41f64fb8be3fbecd8a40f73161250f31 /pkgs/profpatsch/xdg-open/config.dhall
parentb4248f32786039908c2268b8608b46935fc6c31e (diff)
pkgs/profpatsch: add xdg-open, WIP
Diffstat (limited to 'pkgs/profpatsch/xdg-open/config.dhall')
-rw-r--r--pkgs/profpatsch/xdg-open/config.dhall119
1 files changed, 119 insertions, 0 deletions
diff --git a/pkgs/profpatsch/xdg-open/config.dhall b/pkgs/profpatsch/xdg-open/config.dhall
new file mode 100644
index 00000000..32b5d7cf
--- /dev/null
+++ b/pkgs/profpatsch/xdg-open/config.dhall
@@ -0,0 +1,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
+    }