From 284b8d94d41e0c0c7842749c6e69db6a72ad1df3 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 8 Dec 2019 21:11:08 +0100 Subject: [PATCH] readline: add variables option Also add a basic test case. --- modules/programs/readline.nix | 25 +++++++++++++- tests/default.nix | 1 + tests/modules/programs/readline/default.nix | 3 ++ .../programs/readline/using-all-options.nix | 33 +++++++++++++++++++ .../programs/readline/using-all-options.txt | 11 +++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/readline/default.nix create mode 100644 tests/modules/programs/readline/using-all-options.nix create mode 100644 tests/modules/programs/readline/using-all-options.txt diff --git a/modules/programs/readline.nix b/modules/programs/readline.nix index 250f44916..35cbab5f5 100644 --- a/modules/programs/readline.nix +++ b/modules/programs/readline.nix @@ -6,6 +6,19 @@ let cfg = config.programs.readline; + mkSetVariableStr = n: v: + let + mkValueStr = v: + if v == true then "on" + else if v == false then "off" + else if isInt v then toString v + else if isString v then v + else abort ("values ${toPretty v} is of unsupported type"); + in + "set ${n} ${mkValueStr v}"; + + mkBindingStr = k: v: "\"${k}\": ${v}"; + in { @@ -19,6 +32,15 @@ in 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; @@ -40,7 +62,8 @@ in let configStr = concatStringsSep "\n" ( optional cfg.includeSystemConfig "$include /etc/inputrc" - ++ mapAttrsToList (k: v: "\"${k}\": ${v}") cfg.bindings + ++ mapAttrsToList mkSetVariableStr cfg.variables + ++ mapAttrsToList mkBindingStr cfg.bindings ); in '' diff --git a/tests/default.nix b/tests/default.nix index ecb98e141..318e549b1 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -47,6 +47,7 @@ import nmt { // import ./modules/programs/bash // import ./modules/programs/gpg // import ./modules/programs/newsboat + // import ./modules/programs/readline // import ./modules/programs/ssh // import ./modules/programs/tmux // import ./modules/programs/zsh; diff --git a/tests/modules/programs/readline/default.nix b/tests/modules/programs/readline/default.nix new file mode 100644 index 000000000..767d88bfa --- /dev/null +++ b/tests/modules/programs/readline/default.nix @@ -0,0 +1,3 @@ +{ + readline-using-all-options = ./using-all-options.nix; +} diff --git a/tests/modules/programs/readline/using-all-options.nix b/tests/modules/programs/readline/using-all-options.nix new file mode 100644 index 000000000..f50117679 --- /dev/null +++ b/tests/modules/programs/readline/using-all-options.nix @@ -0,0 +1,33 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + programs.readline = { + enable = true; + + bindings = { + "\C-h" = "backward-kill-word"; + }; + + variables = { + bell-style = "audible"; + completion-map-case = true; + completion-prefix-display-length = 2; + }; + + extraConfig = '' + $if mode=emacs + "\e[1~": beginning-of-line + $endif + ''; + }; + + nmt.script = '' + assertFileContent \ + home-files/.inputrc \ + ${./using-all-options.txt} + ''; + }; +} diff --git a/tests/modules/programs/readline/using-all-options.txt b/tests/modules/programs/readline/using-all-options.txt new file mode 100644 index 000000000..da9f7df68 --- /dev/null +++ b/tests/modules/programs/readline/using-all-options.txt @@ -0,0 +1,11 @@ +# Generated by Home Manager. + +$include /etc/inputrc +set bell-style audible +set completion-map-case on +set completion-prefix-display-length 2 +"C-h": backward-kill-word +$if mode=emacs +"\e[1~": beginning-of-line +$endif +