forked from mirrors/nixpkgs
2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
108 lines
3.5 KiB
Nix
108 lines
3.5 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.programs.zsh.syntaxHighlighting;
|
|
in
|
|
{
|
|
imports = [
|
|
(mkRenamedOptionModule [ "programs" "zsh" "enableSyntaxHighlighting" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
|
|
(mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "enable" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
|
|
(mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "highlighters" ] [ "programs" "zsh" "syntaxHighlighting" "highlighters" ])
|
|
(mkRenamedOptionModule [ "programs" "zsh" "syntax-highlighting" "patterns" ] [ "programs" "zsh" "syntaxHighlighting" "patterns" ])
|
|
];
|
|
|
|
options = {
|
|
programs.zsh.syntaxHighlighting = {
|
|
enable = mkEnableOption "zsh-syntax-highlighting";
|
|
|
|
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"
|
|
]));
|
|
|
|
description = lib.mdDoc ''
|
|
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
|
|
'';
|
|
};
|
|
|
|
patterns = mkOption {
|
|
default = {};
|
|
type = types.attrsOf types.str;
|
|
|
|
example = literalExpression ''
|
|
{
|
|
"rm -rf *" = "fg=white,bold,bg=red";
|
|
}
|
|
'';
|
|
|
|
description = lib.mdDoc ''
|
|
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
|
|
'';
|
|
};
|
|
styles = mkOption {
|
|
default = {};
|
|
type = types.attrsOf types.str;
|
|
|
|
example = literalExpression ''
|
|
{
|
|
"alias" = "fg=magenta,bold";
|
|
}
|
|
'';
|
|
|
|
description = lib.mdDoc ''
|
|
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
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
environment.systemPackages = with pkgs; [ zsh-syntax-highlighting ];
|
|
|
|
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.
|
|
'';
|
|
}
|
|
];
|
|
|
|
programs.zsh.interactiveShellInit = with pkgs;
|
|
lib.mkAfter (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)
|
|
++ optionals (length(attrNames cfg.styles) > 0)
|
|
(mapAttrsToList (
|
|
styles: design:
|
|
"ZSH_HIGHLIGHT_STYLES[${styles}]='${design}'"
|
|
) cfg.styles)
|
|
));
|
|
};
|
|
}
|