2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.less;
|
|
|
|
|
|
|
|
configText = if (cfg.configFile != null) then (builtins.readFile cfg.configFile) else ''
|
|
|
|
#command
|
2024-05-15 15:35:15 +00:00
|
|
|
${builtins.concatStringsSep "\n"
|
|
|
|
(lib.mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
2024-05-15 15:35:15 +00:00
|
|
|
${lib.optionalString cfg.clearDefaultCommands "#stop"}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
#line-edit
|
2024-05-15 15:35:15 +00:00
|
|
|
${builtins.concatStringsSep "\n"
|
|
|
|
(lib.mapAttrsToList (command: action: "${command} ${action}") cfg.lineEditingKeys)
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#env
|
2024-05-15 15:35:15 +00:00
|
|
|
${builtins.concatStringsSep "\n"
|
|
|
|
(lib.mapAttrsToList (variable: values: "${variable}=${values}") cfg.envVariables)
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
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
|
2024-05-15 15:35:15 +00:00
|
|
|
enable = lib.mkEnableOption "less, a file pager";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
package = lib.mkPackageOption pkgs "less" { };
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
configFile = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
2024-05-15 15:35:15 +00:00
|
|
|
example = lib.literalExpression ''"''${pkgs.my-configs}/lesskey"'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
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
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
commands = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
h = "noaction 5\\e(";
|
|
|
|
l = "noaction 5\\e)";
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Defines new command keys.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
clearDefaultCommands = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
lineEditingKeys = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
e = "abort";
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Defines new line-editing keys.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
envVariables = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.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";
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Defines environment variables.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
lessopen = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "|${pkgs.lesspipe}/bin/lesspipe.sh %s";
|
2024-05-15 15:35:15 +00:00
|
|
|
defaultText = lib.literalExpression ''"|''${pkgs.lesspipe}/bin/lesspipe.sh %s"'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
lessclose = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = null;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
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
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
environment.variables = {
|
2024-05-15 15:35:15 +00:00
|
|
|
LESSKEYIN_SYSTEM = builtins.toString lessKey;
|
|
|
|
} // lib.optionalAttrs (cfg.lessopen != null) {
|
2020-04-24 23:36:52 +00:00
|
|
|
LESSOPEN = cfg.lessopen;
|
2024-05-15 15:35:15 +00:00
|
|
|
} // lib.optionalAttrs (cfg.lessclose != null) {
|
2020-04-24 23:36:52 +00:00
|
|
|
LESSCLOSE = cfg.lessclose;
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
warnings = lib.optional (
|
|
|
|
cfg.clearDefaultCommands && (builtins.all (x: x != "quit") (builtins.attrValues cfg.commands))
|
2020-04-24 23:36:52 +00:00
|
|
|
) ''
|
|
|
|
config.programs.less.clearDefaultCommands clears all default commands of less but there is no alternative binding for exiting.
|
|
|
|
Consider adding a binding for 'quit'.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ johnazoidberg ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
}
|