nixos/zsh-syntax-highlighting: refactor
This commit is contained in:
parent
423d96e4f2
commit
7002ca7e1c
|
@ -54,25 +54,25 @@ in
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ];
|
environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ];
|
||||||
|
|
||||||
programs.zsh.interactiveShellInit = with pkgs; with builtins; ''
|
assertions = [
|
||||||
source ${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
{
|
||||||
|
assertion = length(attrNames cfg.patterns) > 0 -> elem "pattern" cfg.highlighters;
|
||||||
${optionalString (length(cfg.highlighters) > 0)
|
message = ''
|
||||||
"ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})"
|
When highlighting patterns, "pattern" needs to be included in the list of highlighters.
|
||||||
}
|
|
||||||
|
|
||||||
${let
|
|
||||||
n = attrNames cfg.patterns;
|
|
||||||
in
|
|
||||||
optionalString (length(n) > 0)
|
|
||||||
(assert(elem "pattern" cfg.highlighters); (foldl (
|
|
||||||
a: b:
|
|
||||||
''
|
|
||||||
${a}
|
|
||||||
ZSH_HIGHLIGHT_PATTERNS+=('${b}' '${attrByPath [b] "" cfg.patterns}')
|
|
||||||
''
|
|
||||||
) "") n)
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
programs.zsh.interactiveShellInit = with pkgs;
|
||||||
|
lib.concatStringsSep "\n" ([
|
||||||
|
"source ${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
||||||
|
] ++ optional (length(cfg.highlighters) > 0)
|
||||||
|
"ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})"
|
||||||
|
++ optionals (length(attrNames cfg.patterns) > 0)
|
||||||
|
(mapAttrsToList (
|
||||||
|
pattern: design:
|
||||||
|
"ZSH_HIGHLIGHT_PATTERNS+=('${pattern}' '${design}')"
|
||||||
|
) cfg.patterns)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue