1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-26 03:39:47 +01:00

zsh: allow enabling syntax highlighters (#4360)

This commit is contained in:
Gutyina Gergő 2023-11-19 19:37:32 +01:00 committed by Mikilio
parent 96e4636bba
commit 2b4ba04853
No known key found for this signature in database
GPG key ID: 5B2F1A890CF33F3F
2 changed files with 14 additions and 0 deletions

View file

@ -226,9 +226,20 @@ let
package = mkPackageOption pkgs "zsh-syntax-highlighting" { }; 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: <https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md>
'';
};
styles = mkOption { styles = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = {};
example = { comment = "fg=black,bold"; };
description = '' description = ''
Custom styles for syntax highlighting. Custom styles for syntax highlighting.
See each highlighter's options: <https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md> See each highlighter's options: <https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md>
@ -624,6 +635,7 @@ in
# https://github.com/zsh-users/zsh-syntax-highlighting#faq # https://github.com/zsh-users/zsh-syntax-highlighting#faq
'' ''
source ${cfg.syntaxHighlighting.package}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 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.concatStringsSep "\n" (
lib.mapAttrsToList lib.mapAttrsToList
(name: value: "ZSH_HIGHLIGHT_STYLES+=(${lib.escapeShellArg name} ${lib.escapeShellArg value})") (name: value: "ZSH_HIGHLIGHT_STYLES+=(${lib.escapeShellArg name} ${lib.escapeShellArg value})")

View file

@ -9,6 +9,7 @@ with lib;
syntaxHighlighting = { syntaxHighlighting = {
enable = true; enable = true;
package = pkgs.hello; package = pkgs.hello;
highlighters = [ "brackets" "pattern" "cursor" ];
styles.comment = "fg=#6c6c6c"; styles.comment = "fg=#6c6c6c";
}; };
}; };
@ -17,6 +18,7 @@ with lib;
nmt.script = '' nmt.script = ''
assertFileContains home-files/.zshrc "source ${pkgs.hello}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" 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')" assertFileContains home-files/.zshrc "ZSH_HIGHLIGHT_STYLES+=('comment' 'fg=#6c6c6c')"
''; '';
}; };