9 cfg = config.programs.zsh.syntaxHighlighting;
13 (lib.mkRenamedOptionModule
14 [ "programs" "zsh" "enableSyntaxHighlighting" ]
15 [ "programs" "zsh" "syntaxHighlighting" "enable" ]
17 (lib.mkRenamedOptionModule
18 [ "programs" "zsh" "syntax-highlighting" "enable" ]
19 [ "programs" "zsh" "syntaxHighlighting" "enable" ]
21 (lib.mkRenamedOptionModule
22 [ "programs" "zsh" "syntax-highlighting" "highlighters" ]
23 [ "programs" "zsh" "syntaxHighlighting" "highlighters" ]
25 (lib.mkRenamedOptionModule
26 [ "programs" "zsh" "syntax-highlighting" "patterns" ]
27 [ "programs" "zsh" "syntaxHighlighting" "patterns" ]
32 programs.zsh.syntaxHighlighting = {
33 enable = lib.mkEnableOption "zsh-syntax-highlighting";
35 highlighters = lib.mkOption {
38 # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
39 type = lib.types.listOf (
52 Specifies the highlighters to be used by zsh-syntax-highlighting.
54 The following defined options can be found here:
55 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
59 patterns = lib.mkOption {
61 type = lib.types.attrsOf lib.types.str;
63 example = lib.literalExpression ''
65 "rm -rf *" = "fg=white,bold,bg=red";
70 Specifies custom patterns to be highlighted by zsh-syntax-highlighting.
72 Please refer to the docs for more information about the usage:
73 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/pattern.md
76 styles = lib.mkOption {
78 type = lib.types.attrsOf lib.types.str;
80 example = lib.literalExpression ''
82 "alias" = "fg=magenta,bold";
87 Specifies custom styles to be highlighted by zsh-syntax-highlighting.
89 Please refer to the docs for more information about the usage:
90 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md
96 config = lib.mkIf cfg.enable {
97 environment.systemPackages = [ pkgs.zsh-syntax-highlighting ];
102 builtins.length (builtins.attrNames cfg.patterns) > 0 -> builtins.elem "pattern" cfg.highlighters;
104 When highlighting patterns, "pattern" needs to be included in the list of highlighters.
109 programs.zsh.interactiveShellInit = lib.mkAfter (
110 lib.concatStringsSep "\n" (
112 "source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
115 builtins.length (cfg.highlighters) > 0
116 ) "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${builtins.concatStringsSep " " cfg.highlighters})"
117 ++ lib.optionals (builtins.length (builtins.attrNames cfg.patterns) > 0) (
119 pattern: design: "ZSH_HIGHLIGHT_PATTERNS+=('${pattern}' '${design}')"
122 ++ lib.optionals (builtins.length (builtins.attrNames cfg.styles) > 0) (
123 lib.mapAttrsToList (styles: design: "ZSH_HIGHLIGHT_STYLES[${styles}]='${design}'") cfg.styles