| 
									
										
										
										
											2017-04-23 21:17:31 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with lib; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							| 
									
										
										
										
											2017-05-09 10:37:54 +02:00
										 |  |  |   cfg = config.programs.zsh.syntaxHighlighting; | 
					
						
							| 
									
										
										
										
											2017-04-23 21:17:31 +02:00
										 |  |  | in | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-12-10 02:51:19 +01:00
										 |  |  |   imports = [ | 
					
						
							|  |  |  |     (mkRenamedOptionModule [ "programs" "zsh" "enableSyntaxHighlighting" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ]) | 
					
						
							|  |  |  |     (mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "enable" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ]) | 
					
						
							|  |  |  |     (mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "highlighters" ] [ "programs" "zsh" "syntaxHighlighting" "highlighters" ]) | 
					
						
							|  |  |  |     (mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "patterns" ] [ "programs" "zsh" "syntaxHighlighting" "patterns" ]) | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |   options = { | 
					
						
							|  |  |  |     programs.zsh.syntaxHighlighting = { | 
					
						
							|  |  |  |       enable = mkEnableOption "zsh-syntax-highlighting"; | 
					
						
							| 
									
										
										
										
											2017-04-23 21:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |       highlighters = mkOption { | 
					
						
							|  |  |  |         default = [ "main" ]; | 
					
						
							| 
									
										
										
										
											2017-04-25 16:00:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |         # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md | 
					
						
							|  |  |  |         type = types.listOf(types.enum([ | 
					
						
							|  |  |  |           "main" | 
					
						
							|  |  |  |           "brackets" | 
					
						
							|  |  |  |           "pattern" | 
					
						
							|  |  |  |           "cursor" | 
					
						
							|  |  |  |           "root" | 
					
						
							|  |  |  |           "line" | 
					
						
							|  |  |  |         ])); | 
					
						
							| 
									
										
										
										
											2017-04-25 16:00:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           Specifies the highlighters to be used by zsh-syntax-highlighting. | 
					
						
							| 
									
										
										
										
											2017-04-23 21:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |           The following defined options can be found here: | 
					
						
							|  |  |  |           https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2017-04-29 13:15:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |       patterns = mkOption { | 
					
						
							|  |  |  |         default = {}; | 
					
						
							| 
									
										
										
										
											2019-08-08 22:48:27 +02:00
										 |  |  |         type = types.attrsOf types.str; | 
					
						
							| 
									
										
										
										
											2017-04-29 13:15:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |         example = literalExample ''
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             "rm -rf *" = "fg=white,bold,bg=red"; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2017-04-29 13:15:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           Specifies custom patterns to be highlighted by zsh-syntax-highlighting. | 
					
						
							| 
									
										
										
										
											2017-04-29 13:15:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |           Please refer to the docs for more information about the usage: | 
					
						
							|  |  |  |           https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/pattern.md | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2017-04-23 21:17:31 +02:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2019-01-03 01:05:45 +03:00
										 |  |  |       styles = mkOption { | 
					
						
							|  |  |  |         default = {}; | 
					
						
							| 
									
										
										
										
											2019-08-08 22:48:27 +02:00
										 |  |  |         type = types.attrsOf types.str; | 
					
						
							| 
									
										
										
										
											2019-01-03 01:05:45 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         example = literalExample ''
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             "alias" = "fg=magenta,bold"; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Specifies custom styles to be highlighted by zsh-syntax-highlighting. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Please refer to the docs for more information about the usage: | 
					
						
							|  |  |  |           https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2017-04-23 21:17:31 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2017-04-23 21:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |   config = mkIf cfg.enable { | 
					
						
							|  |  |  |     environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ]; | 
					
						
							| 
									
										
										
										
											2017-04-23 21:17:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |     assertions = [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         assertion = length(attrNames cfg.patterns) > 0 -> elem "pattern" cfg.highlighters; | 
					
						
							|  |  |  |         message = ''
 | 
					
						
							|  |  |  |           When highlighting patterns, "pattern" needs to be included in the list of highlighters. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2017-04-29 13:15:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |     programs.zsh.interactiveShellInit = with pkgs; | 
					
						
							| 
									
										
										
										
											2019-10-23 11:54:52 -03:00
										 |  |  |       lib.mkAfter (lib.concatStringsSep "\n" ([ | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |         "source ${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" | 
					
						
							|  |  |  |       ] ++ optional (length(cfg.highlighters) > 0) | 
					
						
							|  |  |  |         "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})" | 
					
						
							|  |  |  |         ++ optionals (length(attrNames cfg.patterns) > 0) | 
					
						
							|  |  |  |           (mapAttrsToList ( | 
					
						
							|  |  |  |             pattern: design: | 
					
						
							|  |  |  |             "ZSH_HIGHLIGHT_PATTERNS+=('${pattern}' '${design}')" | 
					
						
							|  |  |  |           ) cfg.patterns) | 
					
						
							| 
									
										
										
										
											2019-01-03 01:05:45 +03:00
										 |  |  |         ++ optionals (length(attrNames cfg.styles) > 0) | 
					
						
							|  |  |  |           (mapAttrsToList ( | 
					
						
							|  |  |  |             styles: design: | 
					
						
							|  |  |  |             "ZSH_HIGHLIGHT_STYLES[${styles}]='${design}'" | 
					
						
							|  |  |  |           ) cfg.styles) | 
					
						
							| 
									
										
										
										
											2019-10-23 11:54:52 -03:00
										 |  |  |       )); | 
					
						
							| 
									
										
										
										
											2017-10-09 17:04:21 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | } |