From 0925f79d561b077c40c53e3fb213df461bdf2b06 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 30 May 2017 06:55:03 +0200 Subject: [PATCH 1/2] programs.zsh.syntaxHighlighting: refactor to use attr sets rather than recursive lists for patterns The idea has been described here: https://github.com/NixOS/nixpkgs/pull/25323#issuecomment-298677369 --- .../programs/zsh/zsh-syntax-highlighting.nix | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix b/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix index 39176b28784..1dded038795 100644 --- a/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix +++ b/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix @@ -39,12 +39,12 @@ in patterns = mkOption { default = []; - type = types.listOf(types.listOf(types.string)); + type = types.attrsOf types.string; example = literalExample '' - [ - ["rm -rf *" "fg=white,bold,bg=red"] - ] + { + "rm -rf *" = "fg=white,bold,bg=red"; + } ''; description = '' @@ -67,14 +67,17 @@ in "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})" } - ${optionalString (length(cfg.patterns) > 0) - (assert(elem "pattern" cfg.highlighters); (foldl ( - a: b: - assert(length(b) == 2); '' - ${a} - ZSH_HIGHLIGHT_PATTERNS+=('${elemAt b 0}' '${elemAt b 1}') - '' - ) "") cfg.patterns) + ${let + n = attrNames cfg.patterns; + in + optionalString (length(n) > 0) + (assert(elem "pattern" cfg.highlighters); (foldl ( + a: b: + '' + ${a} + ZSH_HIGHLIGHT_PATTERNS+=('${b}' '${attrByPath [b] "" cfg.patterns}') + '' + ) "") n) } ''; }; From c4e4071ed115aca6ad8e7a15429638b2c497e790 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Tue, 30 May 2017 14:40:25 +0200 Subject: [PATCH 2/2] programs.zsh.syntax-highlighting: simplify enable option by using `mkEnableOption` --- nixos/modules/programs/zsh/zsh-syntax-highlighting.nix | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix b/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix index 1dded038795..3bd7ab81896 100644 --- a/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix +++ b/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix @@ -8,13 +8,7 @@ in { options = { programs.zsh.syntaxHighlighting = { - enable = mkOption { - default = false; - type = types.bool; - description = '' - Enable zsh-syntax-highlighting. - ''; - }; + enable = mkEnableOption "zsh-syntax-highlighting"; highlighters = mkOption { default = [ "main" ];