diff options
Diffstat (limited to 'pkgs/profpatsch/xdg-open/default.nix')
-rw-r--r-- | pkgs/profpatsch/xdg-open/default.nix | 92 |
1 files changed, 67 insertions, 25 deletions
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 { |