lsd: allow user to configure colors

Signed-off-by: Avimitin <dev@avimit.in>
This commit is contained in:
Avimitin 2023-09-22 14:38:30 +08:00 committed by Robert Helgesson
parent 2d27bdcd64
commit 835465e8ba
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
6 changed files with 95 additions and 0 deletions

View File

@ -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
<https://github.com/lsd-rs/lsd/tree/v1.0.0#color-theme-file-content> 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;
};

View File

@ -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

View File

@ -0,0 +1 @@
{ lsd-example-settings = ./example-settings.nix; }

View File

@ -0,0 +1,8 @@
date:
day-old: green
older: dark_green
size:
large: dark_yellow
medium: yellow
none: grey
small: grey

View File

@ -0,0 +1,14 @@
blocks:
- date
- size
- name
color:
theme: custom
date: relative
ignore-globs:
- .git
- .hg
- .bsp
layout: oneline
sorting:
dir-grouping: first

View File

@ -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}
'';
};
}