about summary refs log tree commit diff stats
path: root/home-manager/config/lf/default.nix
blob: 5dfbad7345b9bfe8cfabb36c6b29a6ed8b6bec7c (plain) (blame)
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
{
  config,
  pkgs,
  sysLib,
  ...
}: let
  functionCall = {
    file,
    dependencies,
    ...
  }:
    sysLib.makeShellScriptWithLibrary {
      name = "${builtins.baseNameOf file}";
      script = file;
      dependencies = dependencies ++ (builtins.attrValues {inherit (pkgs) dash;});
    }
    + "/bin/${builtins.baseNameOf file}";
  shell = {
    file,
    dependencies,
    ...
  }: ''
    ''${{
      exec ${functionCall {inherit file dependencies;}}
    }}
  ''; # closes the lf tui
  pipe = {
    file,
    dependencies,
    ...
  }: ''
    %{{
      exec ${functionCall {inherit file dependencies;}}
    }}
  ''; # runs the command in the ui/term bar
  async = {
    file,
    dependencies,
    ...
  }: ''
    &{{
      exec ${functionCall {inherit file dependencies;}}
    }}
  ''; # runs the command in the background
  wait = {
    file,
    dependencies,
    ...
  }: ''
    !{{
      exec ${functionCall {inherit file dependencies;}}
    }}
  ''; # adds a prompt after the command has run
in {
  xdg.configFile."lf/icons".source = ./icons;
  xdg.configFile."lf/colors".source = ./colors;

  programs.lf = {
    enable = true;

    commands = {
      help = shell {
        file = ./cmds/help.sh;
        dependencies = [];
      };
      open = shell {
        file = ./cmds/open.sh;
        dependencies = builtins.attrValues {inherit (pkgs) file xdg-utils;};
      };
      mk_dir = pipe {
        file = ./cmds/mk_dir.sh;
        dependencies = [];
      };
      mk_scr = shell {
        file = ./cmds/mk_scr.sh;
        dependencies = [];
      };
      mk_file = shell {
        file = ./cmds/mk_file.sh;
        dependencies = [];
      };
      chmod = pipe {
        file = ./cmds/chmod.sh;
        dependencies = [];
      };
      mk_ln = pipe {
        file = ./cmds/mk_ln.sh;
        dependencies = [];
      };
      sudo_mk_file = shell {
        file = ./cmds/sudo_mk_file.sh;
        dependencies = [];
      };
      set_wall_paper = pipe {
        file = ./cmds/set_wall_paper.sh;
        dependencies = [];
      };
      fzf_jump = shell {
        file = ./cmds/fzf_jump.sh;
        dependencies = builtins.attrValues {
          inherit (pkgs) fzf;
        };
      };
      broot_jump = shell {
        file = ./cmds/broot_jump.sh;
        dependencies = builtins.attrValues {
          inherit (pkgs) broot;
        };
      };
      open_config = shell {
        file = ./cmds/open_config.sh;
        dependencies = builtins.attrValues {
          #inherit
          #(pkgs)
          ## TODO rewrite this:  bookmenu, https://github.com/jarun/buku
          #
          #buku
          #;
        };
      };

      dragon = pipe {
        file = ./cmds/dragon.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            xdragon
            ;
        };
      };
      dragon_stay = pipe {
        file = ./cmds/dragon_stay.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            xdragon
            ;
        };
      };
      dragon_individual = pipe {
        file = ./cmds/dragon_individual.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            xdragon
            ;
        };
      };
      dl_file = pipe {
        file = ./cmds/dl_file.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            xdragon
            curl
            ;
        };
      };

      unarchive = pipe {
        file = ./cmds/unarchive.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            gnutar
            unzip
            # TODO this is unfree! unrar

            p7zip
            ;
        };
      };
      archive = pipe {
        file = ./cmds/archive.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            fzf
            gnutar
            xz
            p7zip
            zip
            ;
        };
      };

      trash = pipe {
        file = ./cmds/trash.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            trashy
            ;
        };
      };
      clear_trash = pipe {
        file = ./cmds/clear_trash.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            fzf
            trashy
            ;
        };
      };
      restore_trash = shell {
        file = ./cmds/restore_trash.sh;
        dependencies = builtins.attrValues {
          inherit
            (pkgs)
            fzf
            trashy
            ;
        };
      };

      stripspace = pipe {
        file = ./cmds/stripspace.sh;
        dependencies = [];
      };
    };
    keybindings = {
      # Remove some defaults
      m = null;
      "'" = null;
      #" = null; # TODO
      d = null;
      c = null;
      e = null;
      j = null;
      k = null;
      l = null;
      ";" = null;

      # File Openers
      ee = "\$\$EDITOR \"$f\"";
      u = "%\$IVIEWER \"$f\"";
      cc = "\$sudo -e \"$f\"";

      # Archive Mappings
      au = "unarchive";
      a = "archive";

      # Trash Mappings
      dd = "trash";
      jc = "clear_trash";
      jr = "restore_trash";

      # Broot Mapping
      f = "broot_jump";

      # Dragon Mapping
      dr = "dragon";
      ds = "dragon-stay";
      di = "dragon-individual";
      #dm = "mvdragon";
      #dc = "cpdragon";
      dl = "dlfile";

      ss = "stripspace";

      # Vim keys
      h = "updir";
      t = "down";
      n = "up";
      s = "open";

      # Basic Functions
      bn = "help";
      kk = "mklkn";
      "." = "set hidden!";
      DD = "delete";
      p = "paste";
      x = "cut";
      y = "copy";
      "<enter>" = "open";
      mf = "mkfile";
      mr = "sudomkfile";
      md = "mkdir";
      ms = "mkscr";
      ch = "chmod";
      bg = "setwallpaper";
      o = "open_config";
      br = "\$vimv \$fx"; # TODO what is this command?
      r = "rename";
      H = "top";
      L = "bottom";
      R = "reload";
      C = "clear";
      U = "unselect";

      # Movement
      gjr = "cd ~/.local/share/Trash/files";
      gus = "cd /run/dt";

      "gr." = "cd /home/dt/repos";
      grr = "cd /home/dt/repos/rust";
      grp = "cd /home/dt/repos/python";
      grc = "cd /home/dt/repos/c";
      gra = "cd /home/dt/repos/auto_hot_key";
      grt = "cd /home/dt/repos/tex";
      grs = "cd /home/dt/repos/shell";

      grch = "cd /home/dt/repos/chroot";
      grpe = "cd /home/dt/repos/perl";
      grja = "cd /home/dt/repos/java";
      grjs = "cd /home/dt/repos/java_script";
      # -------------
      "gm." = "cd /home/dt/media";
      gmpi = "cd /home/dt/media/pictures";
      gmdo = "cd /home/dt/media/downloads";
      gmpl = "cd /home/dt/media/playlist";
      gmis = "cd /home/dt/media/isos";
      # -------------
      "gs." = "cd /home/dt/school";
      gsgs = "cd /home/dt/school/geschichte";
      gsch = "cd /home/dt/school/chemie";
      gsen = "cd /home/dt/school/english";
      gsgo = "cd /home/dt/school/geographie";
      gsin = "cd /home/dt/school/infomatik";
      gsso = "cd /home/dt/school/sozialkunde";
      gskr = "cd /home/dt/school/katholische_religion";
      gsmu = "cd /home/dt/school/musik";
      gsla = "cd /home/dt/school/latein";
      gsde = "cd /home/dt/school/deutsch";
      gsma = "cd /home/dt/school/mathematik";
      gspr = "cd /home/dt/school/praktikum";
      gsbi = "cd /home/dt/school/biologie";
      gssp = "cd /home/dt/school/sport";
      gsphy = "cd /home/dt/school/physik";
      gsphi = "cd /home/dt/school/philosophie";

      gc = "cd ~/.config";
      gl = "cd ~/.local";
      gE = "cd /etc";

      "gU." = "cd /usr";
      gUs = " cd /usr/share";

      gt = "cd /tmp";
    };
    # TODO add ctpv, if it gets merged
    #   previewer = {
    #      keybinding = "i";
    #      source = pkgs.ctpv;
    #    };
    settings = {
      # TODO this needs to be added to nixos:
      #autoquit = true; # quit the server, if no clients are left
      #dirpreviews = true; # preview for directories

      dircounts = true; # count things in directories TODO this has performance impact
      drawbox = true;
      # errorfmt = "\\033[1;91m==> ERROR:\\033[0m\\033[1;93m%s\\033[0m";
      errorfmt = "\\033[1;91m%s\\033[0m";
      hidden = true; # show hidden files
      icons = true;
      ifs = "\\n"; # internal field separator for shell commands
      info = "size"; # show the size of a directory
      shell = "sh";
      shellopts = "-eu"; # e: exit on error; u: error for unset variables
    };
    # TODO remove auto quit, if it has been added
    # TODO add ctpv, if it gets merged
    extraConfig =
      # &ctpv -s $id
      # &ctpvquit $id
      # set cleaner = {pkgs.ctpv}
      ''
        set autoquit = true
        set dirpreviews = true
      '';
  };
}
# vim: ts=2