about summary refs log tree commit diff
path: root/pkgs/profpatsch/xdg-open
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2020-05-10 00:12:12 +0200
committerProfpatsch <mail@profpatsch.de>2020-05-10 00:12:12 +0200
commitb97e85f21b082e9f06f3ef1655cc0c15c3b2e472 (patch)
treebbe573676796a1dab8a34c01e97614be256e1ba0 /pkgs/profpatsch/xdg-open
parent0adf4290a0eaab8b907d34f66c4831c3493b25fb (diff)
pkgs/profpatsch/xdg-open: implement special commands
Diffstat (limited to 'pkgs/profpatsch/xdg-open')
-rw-r--r--pkgs/profpatsch/xdg-open/config.dhall8
-rw-r--r--pkgs/profpatsch/xdg-open/default.nix92
-rw-r--r--pkgs/profpatsch/xdg-open/xdg-open.dhall3
3 files changed, 73 insertions, 30 deletions
diff --git a/pkgs/profpatsch/xdg-open/config.dhall b/pkgs/profpatsch/xdg-open/config.dhall
index 32b5d7cf..0550c94a 100644
--- a/pkgs/profpatsch/xdg-open/config.dhall
+++ b/pkgs/profpatsch/xdg-open/config.dhall
@@ -10,7 +10,7 @@ let Arg = < String : Text | Variable : Text >
 let CommandTemplate =
       λ(templates : Type) → { exe : Executable, args : templates → List Arg }
 
-let Command = CommandTemplate Text
+let Command = CommandTemplate Arg
 
 let mime =
       { text =
@@ -74,7 +74,7 @@ let mimeMatcher =
 
         let oneArg =
                 λ(exe : Executable)
-              → { exe = exe, args = λ(file : Text) → [ Arg.Variable file ] }
+              → { exe = exe, args = λ(file : Arg) → [ file ] }
 
         let m =
               λ(match : Mime) → λ(cmd : Command) → { match = match, cmd = cmd }
@@ -91,11 +91,11 @@ let mimeMatcher =
                 , cmd =
                   { exe = pkgs { package = "gnupg", binary = "gpg" }
                   , args =
-                        λ(file : Text)
+                        λ(file : Arg)
                       → [ Arg.String "--import"
                         , Arg.String "--import-options"
                         , Arg.String "show-only"
-                        , Arg.Variable file
+                        , file
                         ]
                   }
                 }
diff --git a/pkgs/profpatsch/xdg-open/default.nix b/pkgs/profpatsch/xdg-open/default.nix
index a2d914d2..c0806513 100644
--- a/pkgs/profpatsch/xdg-open/default.nix
+++ b/pkgs/profpatsch/xdg-open/default.nix
@@ -3,7 +3,14 @@
 let
   lib = pkgs.lib;
   bins = getBins pkgs.libnotify [ "notify-send" ]
-      // getBins pkgs.file [ "file" ];
+      // getBins pkgs.file [ "file" ]
+      // getBins pkgs.dmenu [ "dmenu" "dmenu_path" ]
+      # TODO: make sure these are the ones from the environment
+      // getBins pkgs.emacs [ "emacsclient" ]
+      // getBins pkgs.firefox [ "firefox" ]
+      // getBins pkgs.lilyterm-git [ "lilyterm" ]
+      // getBins pkgs.ranger [ "ranger" ]
+      ;
 
   notify = msg: {
     exe = writeExecline "notify" { readNArgs = 2; } [
@@ -12,7 +19,7 @@ let
           ];
     args = file: [
       ({String, Variable}: String msg)
-      ({String, Variable}: Variable file)
+      file
     ];
   };
 
@@ -20,6 +27,47 @@ let
     bins.file "-E" "--brief" "--mime-type" "$1"
   ];
 
+  compose-mail-to = {
+    exe = writeExecline "emacs-mail" { readNArgs = 1; } [
+      bins.emacsclient
+        "--create-frame"
+        "--eval"
+        # TODO: this obviously fails if the mail address contains "
+        ''(url-mailto (url-generic-parse-url "''${1}"))''
+    ];
+    args = file: [ file ];
+  };
+
+  open-in-browser = {
+    exe = bins.firefox;
+    args = file: [ file ];
+  };
+
+  open-in-editor = {
+    exe = bins.emacsclient;
+    args = file: [ file ];
+  };
+
+  dmenu-list-binaries-and-exec = {
+    exe = writeExecline "dmenu-query" { readNArgs = 1; } [
+      "backtick" "-in" "cmd" [
+        "pipeline" [ bins.dmenu_path ] bins.dmenu
+      ]
+      "importas" "cmd" "cmd"
+      "$cmd" "$1"
+    ];
+    args = file: [ file ];
+  };
+
+  exec-in-terminal-emulator = {exe, args}: {
+    exe = bins.lilyterm;
+    args = file: [
+      ({Variable, String}: String "--execute")
+      ({Variable, String}: String exe)
+    ] ++ args file;
+  };
+
+
   Prelude =
     let src = (import ./imports.nix { inherit pkgs; }).Prelude;
     # TODO: bs, make dhall version overridable
@@ -30,28 +78,20 @@ let
 
   xdg-open = importDhall2 {
       type = ''
+  let Command = { args : < String : Text | Variable : Text >
+                  → List < String : Text | Variable : Text >
+                , exe : Text }
+  in
   ∀(bins : { get-mime-type : Text })
 → ∀(write-dash : Text → Text → Text)
 → ∀(shellEscape : Text → Text)
 → ∀(pkgs : { binary : Text, package : Text } → Text)
 → ∀ ( special
-    : { compose-mail-to :
-          { args : Text → List < String : Text | Variable : Text >, exe : Text }
-      , dmenu-list-binaries-and-exec :
-          { args : Text → List < String : Text | Variable : Text >, exe : Text }
-      , exec-in-terminal-emulator :
-            ∀ ( args
-              : { args : Text → List < String : Text | Variable : Text >
-                , exe : Text
-                }
-              )
-          → { args : Text → List < String : Text | Variable : Text >
-            , exe : Text
-            }
-      , open-in-browser :
-          { args : Text → List < String : Text | Variable : Text >, exe : Text }
-      , open-in-editor :
-          { args : Text → List < String : Text | Variable : Text >, exe : Text }
+    : { compose-mail-to : Command
+      , dmenu-list-binaries-and-exec : Command
+      , exec-in-terminal-emulator : ∀ ( args: Command) → Command
+      , open-in-browser : Command
+      , open-in-editor : Command
       }
     )
 → Text
@@ -71,13 +111,15 @@ let
     { inherit get-mime-type; }
     pkgs.writers.writeDash
     pkgs.lib.escapeShellArg
-    ({binary, package}: "${lib.getBin pkgs.${package}}/bin/${package}")
+    ({binary, package}: "${lib.getBin pkgs.${package}}/bin/${binary}")
     {
-      compose-mail-to = notify "compose-mail-to";
-      dmenu-list-binaries-and-exec = notify "dmenu";
-      exec-in-terminal-emulator = exec: notify ("to exec: " + lib.generators.toPretty {} exec);
-      open-in-browser = notify "browser";
-      open-in-editor = notify "editor";
+      inherit
+        compose-mail-to
+        open-in-browser
+        open-in-editor
+        dmenu-list-binaries-and-exec
+        exec-in-terminal-emulator
+        ;
     };
 
 in {
diff --git a/pkgs/profpatsch/xdg-open/xdg-open.dhall b/pkgs/profpatsch/xdg-open/xdg-open.dhall
index cbd9654e..8d6648b2 100644
--- a/pkgs/profpatsch/xdg-open/xdg-open.dhall
+++ b/pkgs/profpatsch/xdg-open/xdg-open.dhall
@@ -37,7 +37,7 @@ let shellEscapeCommand =
                         }
                         arg
                   )
-                  (cmd.args file)
+                  (cmd.args (config.Arg.Variable file))
             )
         : Text
 
@@ -73,6 +73,7 @@ let xdg-open =
           → write-dash
               "xdg-open"
               ''
+              set -e
               file="$1"
               mime=$(${bins.get-mime-type} "$file")