From 9a2ce6569752bb00b86c075ade7ffd47242f3827 Mon Sep 17 00:00:00 2001 From: Kiran Ostrolenk Date: Tue, 10 Oct 2023 18:09:38 +0100 Subject: [PATCH] zsh: generalize zsh-history-substring-search Specifically, allow variable expansion for the key codes by switching from single to double quotes. This also adds a helpful suggestion to descriptions. Taken from the project's README, see https://github.com/zsh-users/zsh-history-substring-search/blob/4abed97b6e67eb5590b39bcd59080aa23192f25d/README.md?plain=1#L71-L74) --- modules/programs/zsh.nix | 10 ++++++---- .../modules/programs/zsh/history-substring-search.nix | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index 58f700df..25c988c3 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -204,7 +204,8 @@ let default = [ "^[[A" ]; description = '' The key codes to be used when searching up. - The default of `^[[A` corresponds to the UP key. + The default of `^[[A` may correspond to the UP key -- if not, try + `$terminfo[kcuu1]`. ''; }; searchDownKey = mkOption { @@ -212,7 +213,8 @@ let default = [ "^[[B" ]; description = '' The key codes to be used when searching down. - The default of `^[[B` corresponds to the DOWN key. + The default of `^[[B` may correspond to the DOWN key -- if not, try + `$terminfo[kcud1]`. ''; }; }; @@ -635,11 +637,11 @@ in '' source ${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh ${lib.concatMapStringsSep "\n" - (upKey: "bindkey '${upKey}' history-substring-search-up") + (upKey: "bindkey \"${upKey}\" history-substring-search-up") (lib.toList cfg.historySubstringSearch.searchUpKey) } ${lib.concatMapStringsSep "\n" - (downKey: "bindkey '${downKey}' history-substring-search-down") + (downKey: "bindkey \"${downKey}\" history-substring-search-down") (lib.toList cfg.historySubstringSearch.searchDownKey) } '') diff --git a/tests/modules/programs/zsh/history-substring-search.nix b/tests/modules/programs/zsh/history-substring-search.nix index 4e9054d9..10560b9f 100644 --- a/tests/modules/programs/zsh/history-substring-search.nix +++ b/tests/modules/programs/zsh/history-substring-search.nix @@ -17,9 +17,9 @@ with lib; # 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$" + 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$" ''; }; }