diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 80aeb47c..0a3cac77 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1280,6 +1280,13 @@ in programs installed via Home Manager. ''; } + + { + time = "2019-12-08T19:48:26+00:00"; + message = '' + A new module is available: 'programs.readline'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 99543de0..ded3587e 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -86,6 +86,7 @@ let (loadModule ./programs/password-store.nix { }) (loadModule ./programs/pazi.nix { }) (loadModule ./programs/pidgin.nix { }) + (loadModule ./programs/readline.nix { }) (loadModule ./programs/rofi.nix { }) (loadModule ./programs/rtorrent.nix { }) (loadModule ./programs/skim.nix { }) diff --git a/modules/programs/readline.nix b/modules/programs/readline.nix new file mode 100644 index 00000000..250f4491 --- /dev/null +++ b/modules/programs/readline.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.readline; + +in + +{ + options.programs.readline = { + enable = mkEnableOption "readline"; + + bindings = mkOption { + default = {}; + type = types.attrsOf types.str; + example = { "\C-h" = "backward-kill-word"; }; + description = "Readline bindings."; + }; + + 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 + ~/.inputrc file. + ''; + }; + }; + + config = mkIf cfg.enable { + home.file.".inputrc".text = + let + configStr = concatStringsSep "\n" ( + optional cfg.includeSystemConfig "$include /etc/inputrc" + ++ mapAttrsToList (k: v: "\"${k}\": ${v}") cfg.bindings + ); + in + '' + # Generated by Home Manager. + + ${configStr} + ${cfg.extraConfig} + ''; + }; +}