1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00
home-manager/modules/programs/readline.nix
Austin Horstman 86402a17b6 treewide: flatten single file modules
Some files don't need nesting and can be root level again to reduce
conflicts with other PRs.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-06-23 16:20:26 -05:00

105 lines
2.4 KiB
Nix

{ config, lib, ... }:
let
inherit (lib) mkIf mkOption types;
cfg = config.programs.readline;
mkSetVariableStr =
n: v:
let
mkValueStr =
v:
if v == true then
"on"
else if v == false then
"off"
else if lib.isInt v then
toString v
else if lib.isString v then
v
else
abort "values ${lib.toPretty v} is of unsupported type";
in
"set ${n} ${mkValueStr v}";
mkBindingStr =
k: v:
let
isKeynameNotKeyseq =
k:
builtins.elem (builtins.head (lib.splitString "-" (lib.toLower k))) [
"control"
"meta"
];
in
if isKeynameNotKeyseq k then "${k}: ${v}" else ''"${k}": ${v}'';
in
{
options.programs.readline = {
enable = lib.mkEnableOption "readline";
bindings = mkOption {
default = { };
type = types.attrsOf types.str;
example = lib.literalExpression ''
{ "\\C-h" = "backward-kill-word"; }
'';
description = "Readline bindings.";
};
variables = mkOption {
type = with types; attrsOf (either str (either int bool));
default = { };
example = {
expand-tilde = true;
};
description = ''
Readline customization variable assignments.
'';
};
includeSystemConfig = mkOption {
type = types.bool;
default = true;
description = "Whether to include the system-wide configuration.";
};
extraConfig = mkOption {
type = types.lines;
default = "";
description = ''
Configuration lines appended unchanged to the end of the
{file}`~/.inputrc` file.
'';
};
};
config = mkIf cfg.enable (
let
finalConfig =
let
configStr = lib.concatStringsSep "\n" (
lib.optional cfg.includeSystemConfig "$include /etc/inputrc"
++ lib.mapAttrsToList mkSetVariableStr cfg.variables
++ lib.mapAttrsToList mkBindingStr cfg.bindings
);
in
''
# Generated by Home Manager.
${configStr}
${cfg.extraConfig}
'';
in
lib.mkMerge [
(mkIf (!config.home.preferXdgDirectories) {
home.file.".inputrc".text = finalConfig;
})
(mkIf config.home.preferXdgDirectories {
xdg.configFile.inputrc.text = finalConfig;
home.sessionVariables.INPUTRC = "${config.xdg.configHome}/inputrc";
})
]
);
}