mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 06:01:15 +00:00
programs.zsh.syntaxHighlighting: refactor to use attr sets rather than recursive lists for patterns
The idea has been described here: https://github.com/NixOS/nixpkgs/pull/25323#issuecomment-298677369
This commit is contained in:
parent
a908ad6fd3
commit
0925f79d56
|
@ -39,12 +39,12 @@ in
|
||||||
|
|
||||||
patterns = mkOption {
|
patterns = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
type = types.listOf(types.listOf(types.string));
|
type = types.attrsOf types.string;
|
||||||
|
|
||||||
example = literalExample ''
|
example = literalExample ''
|
||||||
[
|
{
|
||||||
["rm -rf *" "fg=white,bold,bg=red"]
|
"rm -rf *" = "fg=white,bold,bg=red";
|
||||||
]
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -67,14 +67,17 @@ in
|
||||||
"ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})"
|
"ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})"
|
||||||
}
|
}
|
||||||
|
|
||||||
${optionalString (length(cfg.patterns) > 0)
|
${let
|
||||||
(assert(elem "pattern" cfg.highlighters); (foldl (
|
n = attrNames cfg.patterns;
|
||||||
a: b:
|
in
|
||||||
assert(length(b) == 2); ''
|
optionalString (length(n) > 0)
|
||||||
${a}
|
(assert(elem "pattern" cfg.highlighters); (foldl (
|
||||||
ZSH_HIGHLIGHT_PATTERNS+=('${elemAt b 0}' '${elemAt b 1}')
|
a: b:
|
||||||
''
|
''
|
||||||
) "") cfg.patterns)
|
${a}
|
||||||
|
ZSH_HIGHLIGHT_PATTERNS+=('${b}' '${attrByPath [b] "" cfg.patterns}')
|
||||||
|
''
|
||||||
|
) "") n)
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue