Merge pull request #26229 from Ma27/refactor/use-attr-set-for-syntax-highlighting-patterns
programs.zsh.syntaxHighlighting: refactor to use attr sets rather than recursive lists for patterns
This commit is contained in:
commit
d07ad26bfd
@ -8,13 +8,7 @@ in
|
||||
{
|
||||
options = {
|
||||
programs.zsh.syntaxHighlighting = {
|
||||
enable = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
description = ''
|
||||
Enable zsh-syntax-highlighting.
|
||||
'';
|
||||
};
|
||||
enable = mkEnableOption "zsh-syntax-highlighting";
|
||||
|
||||
highlighters = mkOption {
|
||||
default = [ "main" ];
|
||||
@ -39,12 +33,12 @@ in
|
||||
|
||||
patterns = mkOption {
|
||||
default = [];
|
||||
type = types.listOf(types.listOf(types.string));
|
||||
type = types.attrsOf types.string;
|
||||
|
||||
example = literalExample ''
|
||||
[
|
||||
["rm -rf *" "fg=white,bold,bg=red"]
|
||||
]
|
||||
{
|
||||
"rm -rf *" = "fg=white,bold,bg=red";
|
||||
}
|
||||
'';
|
||||
|
||||
description = ''
|
||||
@ -67,14 +61,17 @@ in
|
||||
"ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})"
|
||||
}
|
||||
|
||||
${optionalString (length(cfg.patterns) > 0)
|
||||
${let
|
||||
n = attrNames cfg.patterns;
|
||||
in
|
||||
optionalString (length(n) > 0)
|
||||
(assert(elem "pattern" cfg.highlighters); (foldl (
|
||||
a: b:
|
||||
assert(length(b) == 2); ''
|
||||
${a}
|
||||
ZSH_HIGHLIGHT_PATTERNS+=('${elemAt b 0}' '${elemAt b 1}')
|
||||
''
|
||||
) "") cfg.patterns)
|
||||
${a}
|
||||
ZSH_HIGHLIGHT_PATTERNS+=('${b}' '${attrByPath [b] "" cfg.patterns}')
|
||||
''
|
||||
) "") n)
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user