···
cfg = config.programs.zsh.syntaxHighlighting;
+
programs.zsh.syntaxHighlighting = {
+
enable = mkEnableOption "zsh-syntax-highlighting";
+
highlighters = mkOption {
+
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
+
type = types.listOf(types.enum([
+
Specifies the highlighters to be used by zsh-syntax-highlighting.
+
The following defined options can be found here:
+
https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
+
type = types.attrsOf types.string;
+
example = literalExample ''
+
"rm -rf *" = "fg=white,bold,bg=red";
+
Specifies custom patterns to be highlighted by zsh-syntax-highlighting.
+
Please refer to the docs for more information about the usage:
+
https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/pattern.md
+
config = mkIf cfg.enable {
+
environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ];
+
assertion = length(attrNames cfg.patterns) > 0 -> elem "pattern" cfg.highlighters;
+
When highlighting patterns, "pattern" needs to be included in the list of highlighters.
+
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)
+
"ZSH_HIGHLIGHT_PATTERNS+=('${pattern}' '${design}')"