1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
{ pkgs, getBins, importDhall2, writeExecline, dhall, buildDhallPackage }:
let
lib = pkgs.lib;
bins = getBins pkgs.libnotify [ "notify-send" ]
// 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; } [
bins.notify-send
("\${1} \${2}")
];
args = file: [
({String, Variable}: String msg)
file
];
};
get-mime-type = writeExecline "get-mime-type" { readNArgs = 1; } [
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
in buildDhallPackage {
name = "Prelude";
code = "${src.repo}/${src.mainFile}";
};
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 : Command
, dmenu-list-binaries-and-exec : Command
, exec-in-terminal-emulator : ∀ ( args: Command) → Command
, open-in-browser : Command
, open-in-editor : Command
}
)
→ Text
'';
root = ./.;
main = "xdg-open.dhall";
files = [
"config.dhall"
"imports/Prelude/Text/concatSep"
"imports/Prelude/Text/concatMap"
"imports/Prelude/Text/concat"
"imports/Prelude/List/map"
"imports/Prelude/List/concatMap"
];
deps = [ Prelude ];
}
{ inherit get-mime-type; }
pkgs.writers.writeDash
pkgs.lib.escapeShellArg
({binary, package}: "${lib.getBin pkgs.${package}}/bin/${binary}")
{
inherit
compose-mail-to
open-in-browser
open-in-editor
dmenu-list-binaries-and-exec
exec-in-terminal-emulator
;
};
in {
inherit
xdg-open
Prelude
;
}
|