From 993fb02d20760067b8ee19c713d94cee07037759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gutyina=20Gerg=C5=91?= Date: Sun, 19 Nov 2023 19:37:32 +0100 Subject: [PATCH] zsh: allow enabling syntax highlighters (#4360) --- modules/programs/zsh.nix | 12 ++++++++++++ tests/modules/programs/zsh/syntax-highlighting.nix | 2 ++ 2 files changed, 14 insertions(+) diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index c282c8325..851fb47ac 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -226,9 +226,20 @@ let package = mkPackageOption pkgs "zsh-syntax-highlighting" { }; + highlighters = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "brackets" ]; + description = '' + Highlighters to enable + See the list of highlighters: + ''; + }; + styles = mkOption { type = types.attrsOf types.str; default = {}; + example = { comment = "fg=black,bold"; }; description = '' Custom styles for syntax highlighting. See each highlighter's options: @@ -624,6 +635,7 @@ in # https://github.com/zsh-users/zsh-syntax-highlighting#faq '' source ${cfg.syntaxHighlighting.package}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh + ZSH_HIGHLIGHT_HIGHLIGHTERS+=(${lib.concatStringsSep " " (map lib.escapeShellArg cfg.syntaxHighlighting.highlighters)}) ${lib.concatStringsSep "\n" ( lib.mapAttrsToList (name: value: "ZSH_HIGHLIGHT_STYLES+=(${lib.escapeShellArg name} ${lib.escapeShellArg value})") diff --git a/tests/modules/programs/zsh/syntax-highlighting.nix b/tests/modules/programs/zsh/syntax-highlighting.nix index 73297c8c1..9baf1e437 100644 --- a/tests/modules/programs/zsh/syntax-highlighting.nix +++ b/tests/modules/programs/zsh/syntax-highlighting.nix @@ -9,6 +9,7 @@ with lib; syntaxHighlighting = { enable = true; package = pkgs.hello; + highlighters = [ "brackets" "pattern" "cursor" ]; styles.comment = "fg=#6c6c6c"; }; }; @@ -17,6 +18,7 @@ with lib; nmt.script = '' assertFileContains home-files/.zshrc "source ${pkgs.hello}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" + assertFileContains home-files/.zshrc "ZSH_HIGHLIGHT_HIGHLIGHTERS+=('brackets' 'pattern' 'cursor')" assertFileContains home-files/.zshrc "ZSH_HIGHLIGHT_STYLES+=('comment' 'fg=#6c6c6c')" ''; };