1 { config, lib, pkgs, ... }:
6 cfg = config.programs.zsh.syntaxHighlighting;
10 (mkRenamedOptionModule [ "programs" "zsh" "enableSyntaxHighlighting" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
11 (mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "enable" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
12 (mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "highlighters" ] [ "programs" "zsh" "syntaxHighlighting" "highlighters" ])
13 (mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "patterns" ] [ "programs" "zsh" "syntaxHighlighting" "patterns" ])
17 programs.zsh.syntaxHighlighting = {
18 enable = mkEnableOption (lib.mdDoc "zsh-syntax-highlighting");
20 highlighters = mkOption {
23 # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
24 type = types.listOf(types.enum([
33 description = lib.mdDoc ''
34 Specifies the highlighters to be used by zsh-syntax-highlighting.
36 The following defined options can be found here:
37 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
43 type = types.attrsOf types.str;
45 example = literalExpression ''
47 "rm -rf *" = "fg=white,bold,bg=red";
51 description = lib.mdDoc ''
52 Specifies custom patterns to be highlighted by zsh-syntax-highlighting.
54 Please refer to the docs for more information about the usage:
55 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/pattern.md
60 type = types.attrsOf types.str;
62 example = literalExpression ''
64 "alias" = "fg=magenta,bold";
68 description = lib.mdDoc ''
69 Specifies custom styles to be highlighted by zsh-syntax-highlighting.
71 Please refer to the docs for more information about the usage:
72 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md
78 config = mkIf cfg.enable {
79 environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ];
83 assertion = length(attrNames cfg.patterns) > 0 -> elem "pattern" cfg.highlighters;
85 When highlighting patterns, "pattern" needs to be included in the list of highlighters.
90 programs.zsh.interactiveShellInit = with pkgs;
91 lib.mkAfter (lib.concatStringsSep "\n" ([
92 "source ${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
93 ] ++ optional (length(cfg.highlighters) > 0)
94 "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})"
95 ++ optionals (length(attrNames cfg.patterns) > 0)
98 "ZSH_HIGHLIGHT_PATTERNS+=('${pattern}' '${design}')"
100 ++ optionals (length(attrNames cfg.styles) > 0)
103 "ZSH_HIGHLIGHT_STYLES[${styles}]='${design}'"