Merge pull request #34381 from JohnAZoidberg/less
nixos/less configure less with module
This commit is contained in:
commit
add22af095
|
@ -328,6 +328,7 @@
|
||||||
joelmo = "Joel Moberg <joel.moberg@gmail.com>";
|
joelmo = "Joel Moberg <joel.moberg@gmail.com>";
|
||||||
joelteon = "Joel Taylor <me@joelt.io>";
|
joelteon = "Joel Taylor <me@joelt.io>";
|
||||||
johbo = "Johannes Bornhold <johannes@bornhold.name>";
|
johbo = "Johannes Bornhold <johannes@bornhold.name>";
|
||||||
|
johnazoidberg = "Daniel Schäfer <git@danielschaefer.me>";
|
||||||
johnmh = "John M. Harris, Jr. <johnmh@openblox.org>";
|
johnmh = "John M. Harris, Jr. <johnmh@openblox.org>";
|
||||||
johnramsden = "John Ramsden <johnramsden@riseup.net>";
|
johnramsden = "John Ramsden <johnramsden@riseup.net>";
|
||||||
joko = "Ioannis Koutras <ioannis.koutras@gmail.com>";
|
joko = "Ioannis Koutras <ioannis.koutras@gmail.com>";
|
||||||
|
|
|
@ -84,6 +84,7 @@
|
||||||
./programs/info.nix
|
./programs/info.nix
|
||||||
./programs/java.nix
|
./programs/java.nix
|
||||||
./programs/kbdlight.nix
|
./programs/kbdlight.nix
|
||||||
|
./programs/less.nix
|
||||||
./programs/light.nix
|
./programs/light.nix
|
||||||
./programs/man.nix
|
./programs/man.nix
|
||||||
./programs/mosh.nix
|
./programs/mosh.nix
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
cfg = config.programs.less;
|
||||||
|
|
||||||
|
configFile = ''
|
||||||
|
#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"
|
||||||
|
{ src = pkgs.writeText "lessconfig" configFile; }
|
||||||
|
"${pkgs.less}/bin/lesskey -o $out $src";
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
|
||||||
|
programs.less = {
|
||||||
|
|
||||||
|
enable = mkEnableOption "less";
|
||||||
|
|
||||||
|
commands = mkOption {
|
||||||
|
type = types.attrsOf types.str;
|
||||||
|
default = {};
|
||||||
|
example = {
|
||||||
|
"h" = "noaction 5\e(";
|
||||||
|
"l" = "noaction 5\e)";
|
||||||
|
};
|
||||||
|
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 = {
|
||||||
|
"\e" = "abort";
|
||||||
|
};
|
||||||
|
description = "Defines new line-editing keys.";
|
||||||
|
};
|
||||||
|
|
||||||
|
envVariables = mkOption {
|
||||||
|
type = types.attrsOf types.str;
|
||||||
|
default = {};
|
||||||
|
example = {
|
||||||
|
LESS = "--quit-if-one-screen";
|
||||||
|
};
|
||||||
|
description = "Defines environment variables.";
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
description = ''
|
||||||
|
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).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
|
environment.systemPackages = [ pkgs.less ];
|
||||||
|
|
||||||
|
environment.variables = {
|
||||||
|
"LESSKEY_SYSTEM" = toString lessKey;
|
||||||
|
} // 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 ];
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue