Skip to content

Commit 7f9f692

Browse files
committed
less: list options in correct order
1 parent e4f72ee commit 7f9f692

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

modules/programs/less.nix

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,33 @@ in
6262
xdg.configFile."lesskey" = lib.mkIf (cfg.config != "") { text = cfg.config; };
6363

6464
programs.less.config = lib.mkIf (cfg.options != { }) (
65+
let
66+
color = lib.intersectAttrs {
67+
color = null;
68+
D = null;
69+
} cfg.options;
70+
prompt = lib.intersectAttrs {
71+
prompt = null;
72+
P = null;
73+
} cfg.options;
74+
otherOptions = lib.removeAttrs cfg.options [
75+
"color"
76+
"D"
77+
"P"
78+
"prompt"
79+
];
80+
81+
toCommandLine = lib.cli.toGNUCommandLineShell { };
82+
83+
orderedOptions = [
84+
otherOptions
85+
color # colors need to come after `--use-color`.
86+
prompt # the prompt has to be the last option.
87+
];
88+
in
6589
lib.mkBefore ''
6690
#env
67-
LESS = ${lib.cli.toGNUCommandLineShell { } cfg.options}
91+
LESS = ${lib.concatMapStringsSep " " toCommandLine orderedOptions}
6892
''
6993
);
7094
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
programs.less = {
3+
enable = true;
4+
options = {
5+
color = [
6+
"HkK" # header: gray
7+
"Mkb" # marks: blue
8+
];
9+
prompt = "s%f";
10+
quiet = true;
11+
};
12+
};
13+
14+
nmt.script = ''
15+
assertFileExists home-files/.config/lesskey
16+
assertFileContent home-files/.config/lesskey ${builtins.toFile "lesskey.expected" ''
17+
#env
18+
LESS = --quiet --color HkK --color Mkb --prompt s%f
19+
''}
20+
'';
21+
}

tests/modules/programs/less/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
less-correct-option-order = ./correct-option-order.nix;
23
less-custom-config = ./custom-config.nix;
34
less-custom-options = ./custom-options.nix;
45
less-custom-options-and-config = ./custom-options-and-config.nix;

0 commit comments

Comments
 (0)