2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.zsh.syntaxHighlighting;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
2024-05-15 15:35:15 +00:00
|
|
|
(lib.mkRenamedOptionModule [ "programs" "zsh" "enableSyntaxHighlighting" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "enable" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "highlighters" ] [ "programs" "zsh" "syntaxHighlighting" "highlighters" ])
|
|
|
|
(lib.mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "patterns" ] [ "programs" "zsh" "syntaxHighlighting" "patterns" ])
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.zsh.syntaxHighlighting = {
|
2024-05-15 15:35:15 +00:00
|
|
|
enable = lib.mkEnableOption "zsh-syntax-highlighting";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
highlighters = lib.mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
default = [ "main" ];
|
|
|
|
|
|
|
|
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
|
2024-05-15 15:35:15 +00:00
|
|
|
type = lib.types.listOf(lib.types.enum([
|
2020-04-24 23:36:52 +00:00
|
|
|
"main"
|
|
|
|
"brackets"
|
|
|
|
"pattern"
|
|
|
|
"cursor"
|
2023-01-20 10:41:00 +00:00
|
|
|
"regexp"
|
2020-04-24 23:36:52 +00:00
|
|
|
"root"
|
|
|
|
"line"
|
|
|
|
]));
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
patterns = lib.mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
default = {};
|
2024-05-15 15:35:15 +00:00
|
|
|
type = lib.types.attrsOf lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
example = lib.literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
"rm -rf *" = "fg=white,bold,bg=red";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
2024-05-15 15:35:15 +00:00
|
|
|
styles = lib.mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
default = {};
|
2024-05-15 15:35:15 +00:00
|
|
|
type = lib.types.attrsOf lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
example = lib.literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
"alias" = "fg=magenta,bold";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ pkgs.zsh-syntax-highlighting ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{
|
2024-05-15 15:35:15 +00:00
|
|
|
assertion = builtins.length(builtins.attrNames cfg.patterns) > 0 -> builtins.elem "pattern" cfg.highlighters;
|
2020-04-24 23:36:52 +00:00
|
|
|
message = ''
|
|
|
|
When highlighting patterns, "pattern" needs to be included in the list of highlighters.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
programs.zsh.interactiveShellInit =
|
2020-04-24 23:36:52 +00:00
|
|
|
lib.mkAfter (lib.concatStringsSep "\n" ([
|
2024-05-15 15:35:15 +00:00
|
|
|
"source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
|
|
|
] ++ lib.optional (builtins.length(cfg.highlighters) > 0)
|
|
|
|
"ZSH_HIGHLIGHT_HIGHLIGHTERS=(${builtins.concatStringsSep " " cfg.highlighters})"
|
|
|
|
++ lib.optionals (builtins.length(builtins.attrNames cfg.patterns) > 0)
|
|
|
|
(lib.mapAttrsToList (
|
2020-04-24 23:36:52 +00:00
|
|
|
pattern: design:
|
|
|
|
"ZSH_HIGHLIGHT_PATTERNS+=('${pattern}' '${design}')"
|
|
|
|
) cfg.patterns)
|
2024-05-15 15:35:15 +00:00
|
|
|
++ lib.optionals (builtins.length(builtins.attrNames cfg.styles) > 0)
|
|
|
|
(lib.mapAttrsToList (
|
2020-04-24 23:36:52 +00:00
|
|
|
styles: design:
|
|
|
|
"ZSH_HIGHLIGHT_STYLES[${styles}]='${design}'"
|
|
|
|
) cfg.styles)
|
|
|
|
));
|
|
|
|
};
|
|
|
|
}
|