fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
6.2 KiB230 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.broot;
8
9  tomlFormat = pkgs.formats.toml { };
10
11  settingsModule = {
12    freeformType = tomlFormat.type;
13
14    options = {
15      modal = mkEnableOption "modal (vim) mode";
16
17      verbs = mkOption {
18        type = with types; listOf (attrsOf (either bool str));
19        default = [ ];
20        example = literalExpression ''
21          [
22            { invocation = "p"; execution = ":parent"; }
23            { invocation = "edit"; shortcut = "e"; execution = "$EDITOR {file}" ; }
24            { invocation = "create {subpath}"; execution = "$EDITOR {directory}/{subpath}"; }
25            { invocation = "view"; execution = "less {file}"; }
26            {
27              invocation = "blop {name}\\.{type}";
28              execution = "mkdir {parent}/{type} && ''${pkgs.neovim}/bin/nvim {parent}/{type}/{name}.{type}";
29              from_shell = true;
30            }
31          ]
32        '';
33        description = ''
34          Define new verbs. For more information, see
35          [Verb Definition Attributes](https://dystroy.org/broot/documentation/configuration/#verb-definition-attributes)
36          in the broot documentation.
37
38          The possible attributes are:
39
40          `invocation` (optional)
41          : how the verb is called by the user, with placeholders for arguments
42
43          `execution` (mandatory)
44          : how the verb is executed
45
46          `key` (optional)
47          : a keyboard key triggering execution
48
49          `shortcut` (optional)
50          : an alternate way to call the verb (without
51            the arguments part)
52
53          `leave_broot` (optional)
54          : whether to quit broot on execution
55            (default: `true`)
56
57          `from_shell` (optional)</term>
58          : whether the verb must be executed from the
59            parent shell (default: `false`)
60        '';
61      };
62
63      skin = mkOption {
64        type = types.attrsOf types.str;
65        default = { };
66        example = literalExpression ''
67          {
68            status_normal_fg = "grayscale(18)";
69            status_normal_bg = "grayscale(3)";
70            status_error_fg = "red";
71            status_error_bg = "yellow";
72            tree_fg = "red";
73            selected_line_bg = "grayscale(7)";
74            permissions_fg = "grayscale(12)";
75            size_bar_full_bg = "red";
76            size_bar_void_bg = "black";
77            directory_fg = "lightyellow";
78            input_fg = "cyan";
79            flag_value_fg = "lightyellow";
80            table_border_fg = "red";
81            code_fg = "lightyellow";
82          }
83        '';
84        description = ''
85          Color configuration.
86
87          Complete list of keys (expected to change before the v1 of broot):
88
89          * `char_match`
90          * `code`
91          * `directory`
92          * `exe`
93          * `file`
94          * `file_error`
95          * `flag_label`
96          * `flag_value`
97          * `input`
98          * `link`
99          * `permissions`
100          * `selected_line`
101          * `size_bar_full`
102          * `size_bar_void`
103          * `size_text`
104          * `spinner`
105          * `status_error`
106          * `status_normal`
107          * `table_border`
108          * `tree`
109          * `unlisted`
110
111          Add `_fg` for a foreground color and
112          `_bg` for a background color.
113        '';
114      };
115    };
116  };
117
118  shellInit = shell:
119    # Using mkAfter to make it more likely to appear after other
120    # manipulations of the prompt.
121    mkAfter ''
122      source ${
123        pkgs.runCommand "br.${shell}" { nativeBuildInputs = [ cfg.package ]; }
124        "broot --print-shell-function ${shell} > $out"
125      }
126    '';
127in {
128  meta.maintainers = [ hm.maintainers.aheaume maintainers.dermetfan ];
129
130  imports = [
131    (mkRenamedOptionModule [ "programs" "broot" "modal" ] [
132      "programs"
133      "broot"
134      "settings"
135      "modal"
136    ])
137    (mkRenamedOptionModule [ "programs" "broot" "verbs" ] [
138      "programs"
139      "broot"
140      "settings"
141      "verbs"
142    ])
143    (mkRenamedOptionModule [ "programs" "broot" "skin" ] [
144      "programs"
145      "broot"
146      "settings"
147      "skin"
148    ])
149  ];
150
151  options.programs.broot = {
152    enable = mkEnableOption "Broot, a better way to navigate directories";
153
154    enableBashIntegration = mkOption {
155      default = true;
156      type = types.bool;
157      description = ''
158        Whether to enable Bash integration.
159      '';
160    };
161
162    enableZshIntegration = mkOption {
163      default = true;
164      type = types.bool;
165      description = ''
166        Whether to enable Zsh integration.
167      '';
168    };
169
170    enableFishIntegration = mkOption {
171      default = true;
172      type = types.bool;
173      description = ''
174        Whether to enable Fish integration.
175      '';
176    };
177
178    package = mkOption {
179      type = types.package;
180      default = pkgs.broot;
181      defaultText = literalExpression "pkgs.broot";
182      description = "Package providing broot";
183    };
184
185    settings = mkOption {
186      type = types.submodule settingsModule;
187      default = { };
188      description = "Verbatim config entries";
189    };
190  };
191
192  config = mkIf cfg.enable {
193    home.packages = [ cfg.package ];
194
195    xdg.configFile."broot" = {
196      recursive = true;
197      source = pkgs.symlinkJoin {
198        name = "xdg.configFile.broot";
199        paths = [
200          # Copy all files under /resources/default-conf
201          "${cfg.package.src}/resources/default-conf"
202
203          # Dummy file to prevent broot from trying to reinstall itself
204          (pkgs.writeTextDir "launcher/installed-v1" "")
205        ];
206
207        postBuild = ''
208          ln -s ${
209            tomlFormat.generate "broot-config" cfg.settings
210          } $out/conf.toml
211
212          # Remove conf.hjson, whose content has been merged into programs.broot.settings
213          rm $out/conf.hjson
214        '';
215      };
216    };
217
218    programs.broot.settings = builtins.fromJSON (builtins.readFile
219      (pkgs.runCommand "default-conf.json" {
220        nativeBuildInputs = [ pkgs.hjson ];
221      }
222        "hjson -c ${cfg.package.src}/resources/default-conf/conf.hjson > $out"));
223
224    programs.bash.initExtra = mkIf cfg.enableBashIntegration (shellInit "bash");
225
226    programs.zsh.initExtra = mkIf cfg.enableZshIntegration (shellInit "zsh");
227
228    programs.fish.shellInit = mkIf cfg.enableFishIntegration (shellInit "fish");
229  };
230}