From 8b84e081ed25446ce5070e25b48d0e1d4beea91f Mon Sep 17 00:00:00 2001 From: Icy-Thought Date: Thu, 8 Feb 2024 15:17:24 +0100 Subject: [PATCH] zsh: add patterns option to syntax-highlighting --- modules/programs/zsh.nix | 15 +++++++++++++++ .../modules/programs/zsh/syntax-highlighting.nix | 1 + 2 files changed, 16 insertions(+) diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index 145d7f797..c4520e7a7 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -236,6 +236,16 @@ let ''; }; + patterns = mkOption { + type = types.attrsOf types.str; + default = {}; + example = { "rm -rf *" = "fg=white,bold,bg=red"; }; + description = '' + Custom syntax highlighting for user-defined patterns. + Reference: + ''; + }; + styles = mkOption { type = types.attrsOf types.str; default = {}; @@ -673,6 +683,11 @@ in (name: value: "ZSH_HIGHLIGHT_STYLES+=(${lib.escapeShellArg name} ${lib.escapeShellArg value})") cfg.syntaxHighlighting.styles )} + ${lib.concatStringsSep "\n" ( + lib.mapAttrsToList + (name: value: "ZSH_HIGHLIGHT_PATTERNS+=(${lib.escapeShellArg name} ${lib.escapeShellArg value})") + cfg.syntaxHighlighting.patterns + )} '') (optionalString (cfg.historySubstringSearch.enable or false) diff --git a/tests/modules/programs/zsh/syntax-highlighting.nix b/tests/modules/programs/zsh/syntax-highlighting.nix index 9baf1e437..981cefb63 100644 --- a/tests/modules/programs/zsh/syntax-highlighting.nix +++ b/tests/modules/programs/zsh/syntax-highlighting.nix @@ -11,6 +11,7 @@ with lib; package = pkgs.hello; highlighters = [ "brackets" "pattern" "cursor" ]; styles.comment = "fg=#6c6c6c"; + patterns."rm -rf *" = "fg=white,bold,bg=red"; }; };