diff options
author | WilliButz <wbutz@cyberfnord.de> | 2017-10-09 17:04:21 +0200 |
---|---|---|
committer | Robin Gloster <mail@glob.in> | 2017-10-09 23:30:10 +0200 |
commit | 7002ca7e1ca74ad2ba07a7dcfc68a92b7ea9546c (patch) | |
tree | c8dff7f073755b1dfddbb4753471ec13718a04a5 /nixos/modules/programs | |
parent | 423d96e4f2dbdd09a921c4601e3d3747e60646f2 (diff) | |
download | nixlib-7002ca7e1ca74ad2ba07a7dcfc68a92b7ea9546c.tar nixlib-7002ca7e1ca74ad2ba07a7dcfc68a92b7ea9546c.tar.gz nixlib-7002ca7e1ca74ad2ba07a7dcfc68a92b7ea9546c.tar.bz2 nixlib-7002ca7e1ca74ad2ba07a7dcfc68a92b7ea9546c.tar.lz nixlib-7002ca7e1ca74ad2ba07a7dcfc68a92b7ea9546c.tar.xz nixlib-7002ca7e1ca74ad2ba07a7dcfc68a92b7ea9546c.tar.zst nixlib-7002ca7e1ca74ad2ba07a7dcfc68a92b7ea9546c.zip |
nixos/zsh-syntax-highlighting: refactor
Diffstat (limited to 'nixos/modules/programs')
-rw-r--r-- | nixos/modules/programs/zsh/zsh-syntax-highlighting.nix | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix b/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix index 9452489e2fb4..e7cf17c2c00c 100644 --- a/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix +++ b/nixos/modules/programs/zsh/zsh-syntax-highlighting.nix @@ -5,74 +5,74 @@ with lib; let cfg = config.programs.zsh.syntaxHighlighting; in - { - options = { - programs.zsh.syntaxHighlighting = { - enable = mkEnableOption "zsh-syntax-highlighting"; +{ + options = { + programs.zsh.syntaxHighlighting = { + enable = mkEnableOption "zsh-syntax-highlighting"; - highlighters = mkOption { - default = [ "main" ]; + highlighters = mkOption { + default = [ "main" ]; - # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md - type = types.listOf(types.enum([ - "main" - "brackets" - "pattern" - "cursor" - "root" - "line" - ])); + # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md + type = types.listOf(types.enum([ + "main" + "brackets" + "pattern" + "cursor" + "root" + "line" + ])); - description = '' - Specifies the highlighters to be used by zsh-syntax-highlighting. + description = '' + Specifies the highlighters to be used by zsh-syntax-highlighting. - The following defined options can be found here: - https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md - ''; - }; + The following defined options can be found here: + https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md + ''; + }; - patterns = mkOption { - default = {}; - type = types.attrsOf types.string; + patterns = mkOption { + default = {}; + type = types.attrsOf types.string; - example = literalExample '' - { - "rm -rf *" = "fg=white,bold,bg=red"; - } - ''; + example = literalExample '' + { + "rm -rf *" = "fg=white,bold,bg=red"; + } + ''; - description = '' - Specifies custom patterns to be highlighted by zsh-syntax-highlighting. + description = '' + Specifies custom patterns 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/pattern.md - ''; - }; + 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 + ''; }; }; + }; - config = mkIf cfg.enable { - environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ]; - - programs.zsh.interactiveShellInit = with pkgs; with builtins; '' - source ${zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ]; - ${optionalString (length(cfg.highlighters) > 0) - "ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})" - } + 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. + ''; + } + ]; - ${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) - } - ''; - }; - } + programs.zsh.interactiveShellInit = with pkgs; + lib.concatStringsSep "\n" ([ + "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) + ); + }; +} |