From bb5dea02b9b61c77f3a15a2ffa59f1102a737326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20K=C3=A1n=C4=9B?= Date: Sun, 1 Dec 2019 16:21:58 +0100 Subject: [PATCH] readline: add module Add basic readline configuration (~/.inputrc) management. --- modules/misc/news.nix | 7 +++++ modules/modules.nix | 1 + modules/programs/readline.nix | 53 +++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 modules/programs/readline.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 80aeb47c9..0a3cac77a 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 99543de0f..ded3587eb 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 000000000..250f44916 --- /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} + ''; + }; +}