-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
startup.nix
338 lines (306 loc) · 10.1 KB
/
startup.nix
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.startup;
in
{
meta.maintainers = [ maintainers.GaetanLepage ];
options.plugins.startup = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "startup.nvim";
package = helpers.mkPluginPackageOption "startup.nvim" pkgs.vimPlugins.startup-nvim;
theme = helpers.defaultNullOpts.mkStr "dashboard" ''
Use a pre-defined theme.
'';
sections =
let
sectionType =
with types;
submodule {
options = {
type =
helpers.defaultNullOpts.mkEnumFirstDefault
[
"text"
"mapping"
"oldfiles"
]
''
- "text" -> text that will be displayed
- "mapping" -> create mappings for commands that can be used.
use `mappings.executeCommand` on the commands to execute.
- "oldfiles" -> display oldfiles (can be opened with `mappings.openFile`/`openFileSplit`)
'';
oldfilesDirectory = helpers.defaultNullOpts.mkBool false ''
if the oldfiles of the current directory should be displayed.
'';
align =
helpers.defaultNullOpts.mkEnumFirstDefault
[
"center"
"left"
"right"
]
''
How to align the section.
'';
foldSection = helpers.defaultNullOpts.mkBool false ''
Whether to fold or not.
'';
title = helpers.defaultNullOpts.mkStr "title" ''
Title for the folded section.
'';
margin =
helpers.defaultNullOpts.mkNullable (with types; either (numbers.between 0.0 1.0) ints.positive) 5
''
The margin for left or right alignment.
- if < 1 fraction of screen width
- if > 1 numbers of column
'';
content =
helpers.mkNullOrOption
(
with types;
oneOf [
# for "text" "mapping"
(listOf (either str (listOf str)))
helpers.nixvimTypes.rawLua
# for "oldfiles" sections
(enum [ "" ])
]
)
''
The type of `content` depends on the section `type`:
- "text" -> a list of strings or a function (`rawLua`) that requires a function that returns a table of strings
- "mapping" -> a list of list of strings in the format:
```nix
[
[<displayed_command_name> <command> <mapping>]
[<displayed_command_name> <command> <mapping>]
]
```
Example: `[" Find File" "Telescope find_files" "<leader>ff"]`
- "oldfiles" -> `""`
'';
highlight = helpers.mkNullOrOption types.str ''
Highlight group in which the section text should be highlighted.
'';
defaultColor = helpers.defaultNullOpts.mkStr "#FF0000" ''
A hex color that gets used if you don't specify `highlight`.
'';
oldfilesAmount = helpers.defaultNullOpts.mkUnsignedInt 5 ''
The amount of oldfiles to be displayed.
'';
};
};
in
mkOption {
type = with types; attrsOf sectionType;
default = { };
description = '''';
example = {
header = {
type = "text";
align = "center";
foldSection = false;
title = "Header";
margin = 5;
content.__raw = "require('startup.headers').hydra_header";
highlight = "Statement";
defaultColor = "";
oldfilesAmount = 0;
};
body = {
type = "mapping";
align = "center";
foldSection = true;
title = "Basic Commands";
margin = 5;
content = [
[
" Find File"
"Telescope find_files"
"<leader>ff"
]
[
" Find Word"
"Telescope live_grep"
"<leader>lg"
]
[
" Recent Files"
"Telescope oldfiles"
"<leader>of"
]
[
" File Browser"
"Telescope file_browser"
"<leader>fb"
]
[
" Colorschemes"
"Telescope colorscheme"
"<leader>cs"
]
[
" New File"
"lua require'startup'.new_file()"
"<leader>nf"
]
];
highlight = "String";
defaultColor = "";
oldfilesAmount = 0;
};
};
};
options = {
mappingKeys = helpers.defaultNullOpts.mkBool true ''
Display mapping (e.g. `<leader>ff`).
'';
cursorColumn =
helpers.defaultNullOpts.mkNullable (with types; either (numbers.between 0.0 1.0) ints.positive) 0.5
''
- if < 1, fraction of screen width
- if > 1 numbers of column
'';
after = helpers.defaultNullOpts.mkLuaFn "nil" ''
A function that gets executed at the end.
'';
emptyLinesBetweenMappings = helpers.defaultNullOpts.mkBool true ''
Add an empty line between mapping/commands.
'';
disableStatuslines = helpers.defaultNullOpts.mkBool true ''
Disable status-, buffer- and tablines.
'';
paddings = helpers.defaultNullOpts.mkListOf types.ints.unsigned [ ] ''
Amount of empty lines before each section (must be equal to amount of sections).
'';
};
mappings = {
executeCommand = helpers.defaultNullOpts.mkStr "<CR>" ''
Keymapping to execute a command.
'';
openFile = helpers.defaultNullOpts.mkStr "o" ''
Keymapping to open a file.
'';
openFileSplit = helpers.defaultNullOpts.mkStr "<c-o>" ''
Keymapping to open a file in a split.
'';
openSection = helpers.defaultNullOpts.mkStr "<TAB>" ''
Keymapping to open a section.
'';
openHelp = helpers.defaultNullOpts.mkStr "?" ''
Keymapping to open help.
'';
};
colors = {
background = helpers.defaultNullOpts.mkStr "#1f2227" ''
The background color.
'';
foldedSection = helpers.defaultNullOpts.mkStr "#56b6c2" ''
The color of folded sections.
This can also be changed with the `StartupFoldedSection` highlight group.
'';
};
parts = mkOption {
type = with types; listOf str;
default = [ ];
description = "List all sections in order.";
example = [
"section_1"
"section_2"
];
};
userMappings = mkOption {
type = with types; attrsOf str;
description = "Add your own mappings as key-command pairs.";
default = { };
example = {
"<leader>ff" = "<cmd>Telescope find_files<CR>";
"<leader>lg" = "<cmd>Telescope live_grep<CR>";
};
};
};
config = mkIf cfg.enable {
assertions =
let
sectionNames = attrNames cfg.sections;
numSections = length sectionNames;
in
[
{
assertion = (cfg.options.paddings == null) || (length cfg.options.paddings) == numSections;
message = ''
Nixvim (plugins.startup): Make sure that `plugins.startup.options.paddings` has the same
number of elements as there are sections.
'';
}
{
assertion =
((length cfg.parts) <= numSections) && (all (part: hasAttr part cfg.sections) cfg.parts);
message = ''
Nixvim (plugins.startup): You should not have more section names in `plugins.startup.parts` than you have sections defined.
'';
}
];
extraPlugins = [ cfg.package ];
extraConfigLua =
let
sections = mapAttrs (
name: sectionAttrs: with sectionAttrs; {
inherit type;
oldfiles_directory = oldfilesDirectory;
inherit align;
fold_section = foldSection;
inherit
title
margin
content
highlight
;
default_color = defaultColor;
oldfiles_amount = oldfilesAmount;
}
) cfg.sections;
options =
with cfg.options;
{
mapping_keys = mappingKeys;
cursor_column = cursorColumn;
inherit after;
empty_lines_between_mappings = emptyLinesBetweenMappings;
disable_statuslines = disableStatuslines;
inherit paddings;
}
// cfg.extraOptions;
setupOptions = {
inherit (cfg) theme;
inherit options;
mappings = with cfg.mappings; {
execute_command = executeCommand;
open_file = openFile;
open_file_split = openFileSplit;
open_section = openSection;
open_help = openHelp;
};
colors = with cfg.colors; {
inherit background;
folded_section = foldedSection;
};
inherit (cfg) parts;
} // sections;
in
''
require('startup').setup(${helpers.toLuaObject setupOptions})
''
+ (optionalString (
cfg.userMappings != { }
) "require('startup').create_mappings(${helpers.toLuaObject cfg.userMappings})");
};
}