Skip to content

Commit 1e294f1

Browse files
committed
less: list options in correct order
1 parent 774ebe7 commit 1e294f1

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

modules/programs/less.nix

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,37 @@ 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.toCommandLineShell (k: {
82+
option = if builtins.stringLength k == 1 then "-${k}" else "--${k}";
83+
sep = null; # options and values must be separate strings
84+
explicitBool = false;
85+
});
86+
87+
orderedOptions = lib.filter (x: x != { }) [
88+
otherOptions
89+
color # colors need to come after `--use-color`.
90+
prompt # the prompt has to be the last option.
91+
];
92+
in
6593
lib.mkBefore ''
6694
#env
67-
LESS = ${lib.cli.toGNUCommandLineShell { } cfg.options}
95+
LESS = ${lib.concatMapStringsSep " " toCommandLine orderedOptions}
6896
''
6997
);
7098
};
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)