2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.less;
|
|
|
|
|
|
|
|
configText = if (cfg.configFile != null) then (builtins.readFile cfg.configFile) else ''
|
|
|
|
#command
|
|
|
|
${concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
|
|
|
|
}
|
2023-04-29 16:46:19 +00:00
|
|
|
${optionalString cfg.clearDefaultCommands "#stop"}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
#line-edit
|
|
|
|
${concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (command: action: "${command} ${action}") cfg.lineEditingKeys)
|
|
|
|
}
|
|
|
|
|
|
|
|
#env
|
|
|
|
${concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (variable: values: "${variable}=${values}") cfg.envVariables)
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2021-10-06 13:57:05 +00:00
|
|
|
lessKey = pkgs.writeText "lessconfig" configText;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
programs.less = {
|
|
|
|
|
2021-10-06 13:57:05 +00:00
|
|
|
# note that environment.nix sets PAGER=less, and
|
|
|
|
# therefore also enables this module
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "less");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''"''${pkgs.my-configs}/lesskey"'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Path to lesskey configuration file.
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
{option}`configFile` takes precedence over {option}`commands`,
|
|
|
|
{option}`clearDefaultCommands`, {option}`lineEditingKeys`, and
|
|
|
|
{option}`envVariables`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
commands = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
h = "noaction 5\\e(";
|
|
|
|
l = "noaction 5\\e)";
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Defines new command keys.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
clearDefaultCommands = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Clear all default commands.
|
|
|
|
You should remember to set the quit key.
|
|
|
|
Otherwise you will not be able to leave less without killing it.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
lineEditingKeys = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
e = "abort";
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Defines new line-editing keys.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
envVariables = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
2021-10-06 13:57:05 +00:00
|
|
|
default = {
|
|
|
|
LESS = "-R";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
example = {
|
|
|
|
LESS = "--quit-if-one-screen";
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Defines environment variables.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
lessopen = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "|${pkgs.lesspipe}/bin/lesspipe.sh %s";
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression ''"|''${pkgs.lesspipe}/bin/lesspipe.sh %s"'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Before less opens a file, it first gives your input preprocessor a chance to modify the way the contents of the file are displayed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
lessclose = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-11-21 17:40:18 +00:00
|
|
|
When less closes a file opened in such a way, it will call another program, called the input postprocessor,
|
|
|
|
which may perform any desired clean-up action (such as deleting the replacement file created by LESSOPEN).
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.less ];
|
|
|
|
|
|
|
|
environment.variables = {
|
2021-10-06 13:57:05 +00:00
|
|
|
LESSKEYIN_SYSTEM = toString lessKey;
|
2020-04-24 23:36:52 +00:00
|
|
|
} // optionalAttrs (cfg.lessopen != null) {
|
|
|
|
LESSOPEN = cfg.lessopen;
|
|
|
|
} // optionalAttrs (cfg.lessclose != null) {
|
|
|
|
LESSCLOSE = cfg.lessclose;
|
|
|
|
};
|
|
|
|
|
|
|
|
warnings = optional (
|
|
|
|
cfg.clearDefaultCommands && (all (x: x != "quit") (attrValues cfg.commands))
|
|
|
|
) ''
|
|
|
|
config.programs.less.clearDefaultCommands clears all default commands of less but there is no alternative binding for exiting.
|
|
|
|
Consider adding a binding for 'quit'.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ johnazoidberg ];
|
|
|
|
|
|
|
|
}
|