at 18.09-beta 2.3 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.programs.zsh.syntaxHighlighting; 7in 8{ 9 options = { 10 programs.zsh.syntaxHighlighting = { 11 enable = mkEnableOption "zsh-syntax-highlighting"; 12 13 highlighters = mkOption { 14 default = [ "main" ]; 15 16 # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md 17 type = types.listOf(types.enum([ 18 "main" 19 "brackets" 20 "pattern" 21 "cursor" 22 "root" 23 "line" 24 ])); 25 26 description = '' 27 Specifies the highlighters to be used by zsh-syntax-highlighting. 28 29 The following defined options can be found here: 30 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md 31 ''; 32 }; 33 34 patterns = mkOption { 35 default = {}; 36 type = types.attrsOf types.string; 37 38 example = literalExample '' 39 { 40 "rm -rf *" = "fg=white,bold,bg=red"; 41 } 42 ''; 43 44 description = '' 45 Specifies custom patterns to be highlighted by zsh-syntax-highlighting. 46 47 Please refer to the docs for more information about the usage: 48 https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/pattern.md 49 ''; 50 }; 51 }; 52 }; 53 54 config = mkIf cfg.enable { 55 environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ]; 56 57 assertions = [ 58 { 59 assertion = length(attrNames cfg.patterns) > 0 -> elem "pattern" cfg.highlighters; 60 message = '' 61 When highlighting patterns, "pattern" needs to be included in the list of highlighters. 62 ''; 63 } 64 ]; 65 66 programs.zsh.interactiveShellInit = with pkgs; 67 lib.concatStringsSep "\n" ([ 68 "source ${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" 69 ] ++ optional (length(cfg.highlighters) > 0) 70 "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})" 71 ++ optionals (length(attrNames cfg.patterns) > 0) 72 (mapAttrsToList ( 73 pattern: design: 74 "ZSH_HIGHLIGHT_PATTERNS+=('${pattern}' '${design}')" 75 ) cfg.patterns) 76 ); 77 }; 78}