diff --git a/modules/programs/lsd.nix b/modules/programs/lsd.nix index 59a51a12..c333918a 100644 --- a/modules/programs/lsd.nix +++ b/modules/programs/lsd.nix @@ -45,6 +45,26 @@ in { for supported values. ''; }; + + colors = mkOption { + type = yamlFormat.type; + default = { }; + example = { + size = { + none = "grey"; + small = "yellow"; + large = "dark_yellow"; + }; + }; + description = '' + Configuration written to {file}`$XDG_CONFIG_HOME/lsd/colors.yaml`. See + for + supported colors. + + If this option is non-empty then the `color.theme` option is + automatically set to `"custom"`. + ''; + }; }; config = mkIf cfg.enable { @@ -56,6 +76,13 @@ in { programs.fish.shellAliases = mkIf cfg.enableAliases aliases; + programs.lsd = + mkIf (cfg.colors != { }) { settings.color.theme = "custom"; }; + + xdg.configFile."lsd/colors.yaml" = mkIf (cfg.colors != { }) { + source = yamlFormat.generate "lsd-colors" cfg.colors; + }; + xdg.configFile."lsd/config.yaml" = mkIf (cfg.settings != { }) { source = yamlFormat.generate "lsd-config" cfg.settings; }; diff --git a/tests/default.nix b/tests/default.nix index d719fbd5..605e1aa4 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -96,6 +96,7 @@ import nmt { ./modules/programs/ledger ./modules/programs/less ./modules/programs/lf + ./modules/programs/lsd ./modules/programs/lieer ./modules/programs/man ./modules/programs/mbsync diff --git a/tests/modules/programs/lsd/default.nix b/tests/modules/programs/lsd/default.nix new file mode 100644 index 00000000..6a1454c9 --- /dev/null +++ b/tests/modules/programs/lsd/default.nix @@ -0,0 +1 @@ +{ lsd-example-settings = ./example-settings.nix; } diff --git a/tests/modules/programs/lsd/example-colors-expected.yaml b/tests/modules/programs/lsd/example-colors-expected.yaml new file mode 100644 index 00000000..9247ac9a --- /dev/null +++ b/tests/modules/programs/lsd/example-colors-expected.yaml @@ -0,0 +1,8 @@ +date: + day-old: green + older: dark_green +size: + large: dark_yellow + medium: yellow + none: grey + small: grey diff --git a/tests/modules/programs/lsd/example-settings-expected.yaml b/tests/modules/programs/lsd/example-settings-expected.yaml new file mode 100644 index 00000000..2ddbe6f3 --- /dev/null +++ b/tests/modules/programs/lsd/example-settings-expected.yaml @@ -0,0 +1,14 @@ +blocks: +- date +- size +- name +color: + theme: custom +date: relative +ignore-globs: +- .git +- .hg +- .bsp +layout: oneline +sorting: + dir-grouping: first diff --git a/tests/modules/programs/lsd/example-settings.nix b/tests/modules/programs/lsd/example-settings.nix new file mode 100644 index 00000000..f9217a09 --- /dev/null +++ b/tests/modules/programs/lsd/example-settings.nix @@ -0,0 +1,44 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.lsd = { + enable = true; + enableAliases = false; + settings = { + date = "relative"; + blocks = [ "date" "size" "name" ]; + layout = "oneline"; + sorting.dir-grouping = "first"; + ignore-globs = [ ".git" ".hg" ".bsp" ]; + }; + colors = { + date = { + day-old = "green"; + older = "dark_green"; + }; + size = { + none = "grey"; + small = "grey"; + medium = "yellow"; + large = "dark_yellow"; + }; + }; + }; + + test.stubs.lsd = { }; + + nmt.script = '' + assertFileExists home-files/.config/lsd/config.yaml + assertFileExists home-files/.config/lsd/colors.yaml + assertFileContent \ + home-files/.config/lsd/config.yaml \ + ${./example-settings-expected.yaml} + assertFileContent \ + home-files/.config/lsd/colors.yaml \ + ${./example-colors-expected.yaml} + ''; + }; +}