readline: Add support for keynames (#3947)

Kenames like `Control-n` or `meta-p` should not be quoted or they don't work.

Keyseqs like `\C-p` or `ab` must continue to be quoted.

See also: https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html

Fixes https://github.com/nix-community/home-manager/issues/3611
This commit is contained in:
Nathan Henrie 2023-05-04 11:39:46 -06:00 committed by GitHub
parent ae6d5466bf
commit f3824311a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View file

@ -21,7 +21,14 @@ let
abort ("values ${toPretty v} is of unsupported type"); abort ("values ${toPretty v} is of unsupported type");
in "set ${n} ${mkValueStr v}"; in "set ${n} ${mkValueStr v}";
mkBindingStr = k: v: ''"${k}": ${v}''; mkBindingStr = k: v:
let
isKeynameNotKeyseq = k:
builtins.elem (builtins.head (lib.splitString "-" (toLower k))) [
"control"
"meta"
];
in if isKeynameNotKeyseq k then "${k}: ${v}" else ''"${k}": ${v}'';
in { in {
options.programs.readline = { options.programs.readline = {

View file

@ -7,7 +7,10 @@ with lib;
programs.readline = { programs.readline = {
enable = true; enable = true;
bindings = { "\\C-h" = "backward-kill-word"; }; bindings = {
"\\C-h" = "backward-kill-word";
"Control-p" = ''"whups"'';
};
variables = { variables = {
bell-style = "audible"; bell-style = "audible";

View file

@ -4,6 +4,7 @@ $include /etc/inputrc
set bell-style audible set bell-style audible
set completion-map-case on set completion-map-case on
set completion-prefix-display-length 2 set completion-prefix-display-length 2
Control-p: "whups"
"\C-h": backward-kill-word "\C-h": backward-kill-word
$if mode=emacs $if mode=emacs
"\e[1~": beginning-of-line "\e[1~": beginning-of-line