fork/home-manager

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

Avimitinlsd: allow user to configure colors835465e8

master
2.1 KiB90 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.lsd;
8
9  yamlFormat = pkgs.formats.yaml { };
10
11  aliases = {
12    ls = "${pkgs.lsd}/bin/lsd";
13    ll = "${pkgs.lsd}/bin/lsd -l";
14    la = "${pkgs.lsd}/bin/lsd -A";
15    lt = "${pkgs.lsd}/bin/lsd --tree";
16    lla = "${pkgs.lsd}/bin/lsd -lA";
17    llt = "${pkgs.lsd}/bin/lsd -l --tree";
18  };
19
20in {
21  meta.maintainers = [ ];
22
23  options.programs.lsd = {
24    enable = mkEnableOption "lsd";
25
26    enableAliases = mkOption {
27      default = false;
28      type = types.bool;
29      description = ''
30        Whether to enable recommended lsd aliases.
31      '';
32    };
33
34    settings = mkOption {
35      type = yamlFormat.type;
36      default = { };
37      example = {
38        date = "relative";
39        ignore-globs = [ ".git" ".hg" ];
40      };
41      description = ''
42        Configuration written to
43        {file}`$XDG_CONFIG_HOME/lsd/config.yaml`. See
44        <https://github.com/Peltoche/lsd#config-file-content>
45        for supported values.
46      '';
47    };
48
49    colors = mkOption {
50      type = yamlFormat.type;
51      default = { };
52      example = {
53        size = {
54          none = "grey";
55          small = "yellow";
56          large = "dark_yellow";
57        };
58      };
59      description = ''
60        Configuration written to {file}`$XDG_CONFIG_HOME/lsd/colors.yaml`. See
61        <https://github.com/lsd-rs/lsd/tree/v1.0.0#color-theme-file-content> for
62        supported colors.
63
64        If this option is non-empty then the `color.theme` option is
65        automatically set to `"custom"`.
66      '';
67    };
68  };
69
70  config = mkIf cfg.enable {
71    home.packages = [ pkgs.lsd ];
72
73    programs.bash.shellAliases = mkIf cfg.enableAliases aliases;
74
75    programs.zsh.shellAliases = mkIf cfg.enableAliases aliases;
76
77    programs.fish.shellAliases = mkIf cfg.enableAliases aliases;
78
79    programs.lsd =
80      mkIf (cfg.colors != { }) { settings.color.theme = "custom"; };
81
82    xdg.configFile."lsd/colors.yaml" = mkIf (cfg.colors != { }) {
83      source = yamlFormat.generate "lsd-colors" cfg.colors;
84    };
85
86    xdg.configFile."lsd/config.yaml" = mkIf (cfg.settings != { }) {
87      source = yamlFormat.generate "lsd-config" cfg.settings;
88    };
89  };
90}