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
|
|
|
|
{
|
|
|
|
options = {
|
2017-05-09 10:37:54 +02:00
|
|
|
programs.zsh.syntaxHighlighting = {
|
2017-05-30 14:40:25 +02:00
|
|
|
enable = mkEnableOption "zsh-syntax-highlighting";
|
2017-04-23 21:17:31 +02:00
|
|
|
|
|
|
|
highlighters = mkOption {
|
|
|
|
default = [ "main" ];
|
2017-04-25 16:00:20 +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-23 21:17:31 +02:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
2017-04-29 13:15:42 +02:00
|
|
|
|
|
|
|
patterns = mkOption {
|
2017-06-04 21:23:34 +02:00
|
|
|
default = {};
|
2017-05-30 06:55:03 +02:00
|
|
|
type = types.attrsOf types.string;
|
2017-04-29 13:15:42 +02:00
|
|
|
|
|
|
|
example = literalExample ''
|
2017-05-30 06:55:03 +02:00
|
|
|
{
|
|
|
|
"rm -rf *" = "fg=white,bold,bg=red";
|
|
|
|
}
|
2017-04-29 13:15:42 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
2017-04-23 21:17:31 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
${optionalString (length(cfg.highlighters) > 0)
|
|
|
|
"ZSH_HIGHLIGHT_HIGHLIGHTERS=(${concatStringsSep " " cfg.highlighters})"
|
|
|
|
}
|
2017-04-29 13:15:42 +02:00
|
|
|
|
2017-05-30 06:55:03 +02:00
|
|
|
${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)
|
2017-04-29 13:15:42 +02:00
|
|
|
}
|
2017-04-23 21:17:31 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|