2018-01-20 20:12:40 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.less;
|
|
|
|
|
2018-04-09 02:30:27 +02:00
|
|
|
configText = if (cfg.configFile != null) then (builtins.readFile cfg.configFile) else ''
|
2018-01-20 20:12:40 +01:00
|
|
|
#command
|
|
|
|
${concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
|
|
|
|
}
|
|
|
|
${if cfg.clearDefaultCommands then "#stop" else ""}
|
|
|
|
|
|
|
|
#line-edit
|
|
|
|
${concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (command: action: "${command} ${action}") cfg.lineEditingKeys)
|
|
|
|
}
|
|
|
|
|
|
|
|
#env
|
|
|
|
${concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (variable: values: "${variable}=${values}") cfg.envVariables)
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
lessKey = pkgs.runCommand "lesskey"
|
2018-11-08 11:59:03 +01:00
|
|
|
{ src = pkgs.writeText "lessconfig" configText; preferLocalBuild = true; }
|
2018-01-20 20:12:40 +01:00
|
|
|
"${pkgs.less}/bin/lesskey -o $out $src";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
programs.less = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "less";
|
|
|
|
|
2018-04-09 02:30:27 +02:00
|
|
|
configFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
example = literalExample "$${pkgs.my-configs}/lesskey";
|
|
|
|
description = ''
|
|
|
|
Path to lesskey configuration file.
|
|
|
|
|
|
|
|
<option>configFile</option> takes precedence over <option>commands</option>,
|
|
|
|
<option>clearDefaultCommands</option>, <option>lineEditingKeys</option>, and
|
|
|
|
<option>envVariables</option>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-01-20 20:12:40 +01:00
|
|
|
commands = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
example = {
|
2019-09-17 02:18:14 +02:00
|
|
|
h = "noaction 5\\e(";
|
|
|
|
l = "noaction 5\\e)";
|
2018-01-20 20:12:40 +01:00
|
|
|
};
|
|
|
|
description = "Defines new command keys.";
|
|
|
|
};
|
|
|
|
|
|
|
|
clearDefaultCommands = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
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 = {
|
2019-08-13 23:52:01 +02:00
|
|
|
e = "abort";
|
2018-01-20 20:12:40 +01:00
|
|
|
};
|
|
|
|
description = "Defines new line-editing keys.";
|
|
|
|
};
|
|
|
|
|
|
|
|
envVariables = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
LESS = "--quit-if-one-screen";
|
|
|
|
};
|
|
|
|
description = "Defines environment variables.";
|
|
|
|
};
|
|
|
|
|
2018-01-29 16:08:32 +01:00
|
|
|
lessopen = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "|${pkgs.lesspipe}/bin/lesspipe.sh %s";
|
|
|
|
description = ''
|
|
|
|
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;
|
2018-01-20 20:12:40 +01:00
|
|
|
description = ''
|
2018-01-29 16:08:32 +01: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).
|
2018-01-20 20:12:40 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.less ];
|
|
|
|
|
2018-01-29 16:08:32 +01:00
|
|
|
environment.variables = {
|
2019-08-13 23:52:01 +02:00
|
|
|
LESSKEY_SYSTEM = toString lessKey;
|
2018-01-29 16:08:32 +01:00
|
|
|
} // optionalAttrs (cfg.lessopen != null) {
|
2019-08-13 23:52:01 +02:00
|
|
|
LESSOPEN = cfg.lessopen;
|
2018-01-29 16:08:32 +01:00
|
|
|
} // optionalAttrs (cfg.lessclose != null) {
|
2019-08-13 23:52:01 +02:00
|
|
|
LESSCLOSE = cfg.lessclose;
|
2018-01-29 16:08:32 +01:00
|
|
|
};
|
2018-01-20 20:12:40 +01:00
|
|
|
|
|
|
|
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 ];
|
|
|
|
|
|
|
|
}
|