From 835465e8ba2459034e4ab192b1c6db35d1c0d638 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Fri, 22 Sep 2023 14:38:30 +0800 Subject: [PATCH] lsd: allow user to configure colors Signed-off-by: Avimitin --- modules/programs/lsd.nix | 27 ++++++++++++ tests/default.nix | 1 + tests/modules/programs/lsd/default.nix | 1 + .../programs/lsd/example-colors-expected.yaml | 8 ++++ .../lsd/example-settings-expected.yaml | 14 ++++++ .../modules/programs/lsd/example-settings.nix | 44 +++++++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 tests/modules/programs/lsd/default.nix create mode 100644 tests/modules/programs/lsd/example-colors-expected.yaml create mode 100644 tests/modules/programs/lsd/example-settings-expected.yaml create mode 100644 tests/modules/programs/lsd/example-settings.nix diff --git a/modules/programs/lsd.nix b/modules/programs/lsd.nix index 59a51a12a..c333918a8 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 d719fbd58..605e1aa42 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 000000000..6a1454c9a --- /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 000000000..9247ac9a3 --- /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 000000000..2ddbe6f3f --- /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 000000000..f9217a098 --- /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} + ''; + }; +}