nixos/less configure less with module
This commit is contained in:
parent
959e9336ee
commit
192c2330d0
3 changed files with 125 additions and 0 deletions
|
@ -325,6 +325,7 @@
|
|||
joelmo = "Joel Moberg <joel.moberg@gmail.com>";
|
||||
joelteon = "Joel Taylor <me@joelt.io>";
|
||||
johbo = "Johannes Bornhold <johannes@bornhold.name>";
|
||||
johnazoidberg = "Daniel Schäfer <git@danielschaefer.me>";
|
||||
johnmh = "John M. Harris, Jr. <johnmh@openblox.org>";
|
||||
johnramsden = "John Ramsden <johnramsden@riseup.net>";
|
||||
joko = "Ioannis Koutras <ioannis.koutras@gmail.com>";
|
||||
|
|
|
@ -84,6 +84,7 @@
|
|||
./programs/info.nix
|
||||
./programs/java.nix
|
||||
./programs/kbdlight.nix
|
||||
./programs/less.nix
|
||||
./programs/light.nix
|
||||
./programs/man.nix
|
||||
./programs/mosh.nix
|
||||
|
|
123
nixos/modules/programs/less.nix
Normal file
123
nixos/modules/programs/less.nix
Normal file
|
@ -0,0 +1,123 @@
|
|||
{ 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";
|
||||
|
||||
lessPipe = pkgs.writeScriptBin "lesspipe.sh" ''
|
||||
#! /bin/sh
|
||||
case "$1" in
|
||||
*.gz)
|
||||
${pkgs.gzip}/bin/gunzip --stdout "$1" 2>/dev/null
|
||||
;;
|
||||
*.xz)
|
||||
${pkgs.xz}/bin/unxz --stdout "$1" 2>/dev/null
|
||||
;;
|
||||
*.bz2)
|
||||
${pkgs.bzip2}/bin/bunzip2 --stdout "$1" 2>/dev/null
|
||||
;;
|
||||
*) exit 1
|
||||
;;
|
||||
esac
|
||||
exit $?
|
||||
'';
|
||||
|
||||
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.";
|
||||
};
|
||||
|
||||
autoExtract = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
When enabled less automatically extracts .gz .xz .bz2 files before reading them.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
environment.systemPackages = [ pkgs.less ];
|
||||
|
||||
environment.variables."LESSKEY_SYSTEM" = toString lessKey;
|
||||
environment.variables."LESSOPEN" = "|${lessPipe}/bin/lesspipe.sh %s";
|
||||
|
||||
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 a new issue