mirror of
https://github.com/nix-community/home-manager
synced 2024-11-27 05:29:46 +01:00
zsh: allow multiple bindings to history-substring-search (#3929)
It's pretty common to need multiple bindings to history-substring-search, since different terminals will send different keys for up/down. This does not break back-compatibility, and introduces a new test
This commit is contained in:
parent
27d89b49e3
commit
3144311f31
3 changed files with 40 additions and 8 deletions
|
@ -190,18 +190,18 @@ let
|
||||||
options = {
|
options = {
|
||||||
enable = mkEnableOption "history substring search";
|
enable = mkEnableOption "history substring search";
|
||||||
searchUpKey = mkOption {
|
searchUpKey = mkOption {
|
||||||
type = types.str;
|
type = with types; either (listOf str) str ;
|
||||||
default = "^[[A";
|
default = [ "^[[A" ];
|
||||||
description = ''
|
description = ''
|
||||||
The key code to be used when searching up.
|
The key codes to be used when searching up.
|
||||||
The default of <literal>^[[A</literal> corresponds to the UP key.
|
The default of <literal>^[[A</literal> corresponds to the UP key.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
searchDownKey = mkOption {
|
searchDownKey = mkOption {
|
||||||
type = types.str;
|
type = with types; either (listOf str) str ;
|
||||||
default = "^[[B";
|
default = [ "^[[B" ];
|
||||||
description = ''
|
description = ''
|
||||||
The key code to be used when searching down.
|
The key codes to be used when searching down.
|
||||||
The default of <literal>^[[B</literal> corresponds to the DOWN key.
|
The default of <literal>^[[B</literal> corresponds to the DOWN key.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
@ -593,8 +593,14 @@ in
|
||||||
# https://github.com/zsh-users/zsh-history-substring-search#usage
|
# https://github.com/zsh-users/zsh-history-substring-search#usage
|
||||||
''
|
''
|
||||||
source ${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh
|
source ${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh
|
||||||
bindkey '${cfg.historySubstringSearch.searchUpKey}' history-substring-search-up
|
${lib.concatMapStringsSep "\n"
|
||||||
bindkey '${cfg.historySubstringSearch.searchDownKey}' history-substring-search-down
|
(upKey: "bindkey '${upKey}' history-substring-search-up")
|
||||||
|
(lib.toList cfg.historySubstringSearch.searchUpKey)
|
||||||
|
}
|
||||||
|
${lib.concatMapStringsSep "\n"
|
||||||
|
(downKey: "bindkey '${downKey}' history-substring-search-down")
|
||||||
|
(lib.toList cfg.historySubstringSearch.searchDownKey)
|
||||||
|
}
|
||||||
'')
|
'')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,6 @@
|
||||||
zsh-history-path-old-default = ./history-path-old-default.nix;
|
zsh-history-path-old-default = ./history-path-old-default.nix;
|
||||||
zsh-history-path-old-custom = ./history-path-old-custom.nix;
|
zsh-history-path-old-custom = ./history-path-old-custom.nix;
|
||||||
zsh-history-ignore-pattern = ./history-ignore-pattern.nix;
|
zsh-history-ignore-pattern = ./history-ignore-pattern.nix;
|
||||||
|
zsh-history-substring-search = ./history-substring-search.nix;
|
||||||
zsh-prezto = ./prezto.nix;
|
zsh-prezto = ./prezto.nix;
|
||||||
}
|
}
|
||||||
|
|
25
tests/modules/programs/zsh/history-substring-search.nix
Normal file
25
tests/modules/programs/zsh/history-substring-search.nix
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
programs.zsh = {
|
||||||
|
enable = true;
|
||||||
|
historySubstringSearch = {
|
||||||
|
enable = true;
|
||||||
|
searchDownKey = "^[[B";
|
||||||
|
searchUpKey = [ "^[[A" "\\eOA" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
test.stubs.zsh = { };
|
||||||
|
|
||||||
|
# Written with regex to ensure we don't end up missing newlines in the future
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileRegex home-files/.zshrc "^bindkey '\^\[\[B' history-substring-search-down$"
|
||||||
|
assertFileRegex home-files/.zshrc "^bindkey '\^\[\[A' history-substring-search-up$"
|
||||||
|
assertFileRegex home-files/.zshrc "^bindkey '\\\\eOA' history-substring-search-up$"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue