git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #26229 from Ma27/refactor/use-attr-set-for-syntax-highlighting-patterns

programs.zsh.syntaxHighlighting: refactor to use attr sets rather than recursive lists for patterns

commitd07ad26bfde04522aea577e635bd041f4878f56f authorJörg Thalheim <Mic92@users.noreply.github.com> dateSat 3 Jun 2017, 19:28 (9 years ago) parent4a35514c4e4071
1 file changed+16−19
nixos/modules/programs/zsh/zsh-syntax-highlighting.nix+16−19
nixos/modules/programs/zsh/zsh-syntax-highlighting.nix+16−19
@@ -8,13 +8,7 @@ in
88 {
99 options = {
1010 programs.zsh.syntaxHighlighting = {
11− enable = mkOption {
12− default = false;
13− type = types.bool;
14− description = ''
15− Enable zsh-syntax-highlighting.
16− '';
17− };
11+ enable = mkEnableOption "zsh-syntax-highlighting";
1812
1913 highlighters = mkOption {
2014 default = [ "main" ];
@@ -39,12 +33,12 @@ in
3933
4034 patterns = mkOption {
4135 default = [];
42− type = types.listOf(types.listOf(types.string));
36+ type = types.attrsOf types.string;
4337
4438 example = literalExample ''
45− [
46− ["rm -rf *" "fg=white,bold,bg=red"]
47− ]
39+ {
40+ "rm -rf *" = "fg=white,bold,bg=red";
41+ }
4842 '';
4943
5044 description = ''
@@ -67,14 +61,17 @@ in
6761 "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})"
6862 }
6963
70− ${optionalString (length(cfg.patterns) > 0)
71− (assert(elem "pattern" cfg.highlighters); (foldl (
72− a: b:
73− assert(length(b) == 2); ''
74− ${a}
75− ZSH_HIGHLIGHT_PATTERNS+=('${elemAt b 0}' '${elemAt b 1}')
76− ''
77− ) "") cfg.patterns)
64+ ${let
65+ n = attrNames cfg.patterns;
66+ in
67+ optionalString (length(n) > 0)
68+ (assert(elem "pattern" cfg.highlighters); (foldl (
69+ a: b:
70+ ''
71+ ${a}
72+ ZSH_HIGHLIGHT_PATTERNS+=('${b}' '${attrByPath [b] "" cfg.patterns}')
73+ ''
74+ ) "") n)
7875 }
7976 '';
8077 };