nixos/zsh-autosuggestions: ZSH_AUTOSUGGEST_STRATEGY array

zsh-autosuggestions supports having fallback strategies expressed
through the ZSH_AUTOSUGGEST_STRATEGY array. For example,
`ZSH_AUTOSUGGEST_STRATEGY=(history completion)`. We should also support
this.
This commit is contained in:
Ryan Gibb 2022-03-07 16:29:00 +00:00
parent 42b833c43e
commit 34b5dd453b
3 changed files with 19 additions and 10 deletions

View file

@ -846,6 +846,12 @@
compatibilty, but will be removed at a later date. compatibilty, but will be removed at a later date.
</para> </para>
</listitem> </listitem>
<listitem>
<para>
<literal>programs.zsh.autosuggestions.strategy</literal> now
takes a list of strings instead of a string.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
The <literal>services.unifi.openPorts</literal> option default The <literal>services.unifi.openPorts</literal> option default

View file

@ -278,6 +278,8 @@ In addition to numerous new and upgraded packages, this release has the followin
combined `influxdb2` package is still provided in this release for combined `influxdb2` package is still provided in this release for
backwards compatibilty, but will be removed at a later date. backwards compatibilty, but will be removed at a later date.
- `programs.zsh.autosuggestions.strategy` now takes a list of strings instead of a string.
- The `services.unifi.openPorts` option default value of `true` is now deprecated and will be changed to `false` in 22.11. - The `services.unifi.openPorts` option default value of `true` is now deprecated and will be changed to `false` in 22.11.
Configurations using this default will print a warning when rebuilt. Configurations using this default will print a warning when rebuilt.

View file

@ -22,17 +22,18 @@ in
}; };
strategy = mkOption { strategy = mkOption {
type = types.enum [ "history" "match_prev_cmd" ]; type = types.listOf (types.enum [ "history" "completion" "match_prev_cmd" ]);
default = "history"; default = [ "history" ];
description = '' description = ''
Set ZSH_AUTOSUGGEST_STRATEGY to choose the strategy for generating suggestions. `ZSH_AUTOSUGGEST_STRATEGY` is an array that specifies how suggestions should be generated.
There are currently two to choose from: The strategies in the array are tried successively until a suggestion is found.
There are currently three built-in strategies to choose from:
* history: Chooses the most recent match. - `history`: Chooses the most recent match from history.
* match_prev_cmd: Chooses the most recent match whose preceding history item matches - `completion`: Chooses a suggestion based on what tab-completion would suggest. (requires `zpty` module)
the most recently executed command (more info). Note that this strategy won't work as - `match_prev_cmd`: Like `history`, but chooses the most recent match whose preceding history item matches
expected with ZSH options that don't preserve the history order such as the most recently executed command. Note that this strategy won't work as expected with ZSH options that
HIST_IGNORE_ALL_DUPS or HIST_EXPIRE_DUPS_FIRST. don't preserve the history order such as `HIST_IGNORE_ALL_DUPS` or `HIST_EXPIRE_DUPS_FIRST`.
''; '';
}; };
@ -62,7 +63,7 @@ in
source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.highlightStyle}" export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.highlightStyle}"
export ZSH_AUTOSUGGEST_STRATEGY=("${cfg.strategy}") export ZSH_AUTOSUGGEST_STRATEGY=(${concatStringsSep " " cfg.strategy})
${optionalString (!cfg.async) "unset ZSH_AUTOSUGGEST_USE_ASYNC"} ${optionalString (!cfg.async) "unset ZSH_AUTOSUGGEST_USE_ASYNC"}
${concatStringsSep "\n" (mapAttrsToList (key: value: ''export ${key}="${value}"'') cfg.extraConfig)} ${concatStringsSep "\n" (mapAttrsToList (key: value: ''export ${key}="${value}"'') cfg.extraConfig)}