1 { config, lib, pkgs, ... }:
4 cfg = config.programs.zsh.syntaxHighlighting;
8 (lib.mkRenamedOptionModule [ "programs" "zsh" "enableSyntaxHighlighting" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
9 (lib.mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "enable" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
10 (lib.mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "highlighters" ] [ "programs" "zsh" "syntaxHighlighting" "highlighters" ])
11 (lib.mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "patterns" ] [ "programs" "zsh" "syntaxHighlighting" "patterns" ])
15 programs.zsh.syntaxHighlighting = {
16 enable = lib.mkEnableOption "zsh-syntax-highlighting";
18 highlighters = lib.mkOption {
21 # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
22 type = lib.types.listOf(lib.types.enum([
33 Specifies the highlighters to be used by zsh-syntax-highlighting.
35 The following defined options can be found here:
36 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
40 patterns = lib.mkOption {
42 type = lib.types.attrsOf lib.types.str;
44 example = lib.literalExpression ''
46 "rm -rf *" = "fg=white,bold,bg=red";
51 Specifies custom patterns to be highlighted by zsh-syntax-highlighting.
53 Please refer to the docs for more information about the usage:
54 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/pattern.md
57 styles = lib.mkOption {
59 type = lib.types.attrsOf lib.types.str;
61 example = lib.literalExpression ''
63 "alias" = "fg=magenta,bold";
68 Specifies custom styles to be highlighted by zsh-syntax-highlighting.
70 Please refer to the docs for more information about the usage:
71 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md
77 config = lib.mkIf cfg.enable {
78 environment.systemPackages = [ pkgs.zsh-syntax-highlighting ];
82 assertion = builtins.length(builtins.attrNames cfg.patterns) > 0 -> builtins.elem "pattern" cfg.highlighters;
84 When highlighting patterns, "pattern" needs to be included in the list of highlighters.
89 programs.zsh.interactiveShellInit =
90 lib.mkAfter (lib.concatStringsSep "\n" ([
91 "source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
92 ] ++ lib.optional (builtins.length(cfg.highlighters) > 0)
93 "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${builtins.concatStringsSep " " cfg.highlighters})"
94 ++ lib.optionals (builtins.length(builtins.attrNames cfg.patterns) > 0)
97 "ZSH_HIGHLIGHT_PATTERNS+=('${pattern}' '${design}')"
99 ++ lib.optionals (builtins.length(builtins.attrNames cfg.styles) > 0)
100 (lib.mapAttrsToList (
102 "ZSH_HIGHLIGHT_STYLES[${styles}]='${design}'"