summary refs log tree commit diff
path: root/nixos/modules/programs/zsh/zsh-autosuggestions.nix
diff options
context:
space:
mode:
authorRyan Gibb <ryangibb321@gmail.com>2022-03-07 16:29:00 +0000
committerRyan Gibb <ryangibb321@gmail.com>2022-03-07 16:29:00 +0000
commit34b5dd453b13c2c09334e3def42416b5b2442a0a (patch)
tree7d6ec4bb1fbaf3f00ca82252b77cbe8626b9326d /nixos/modules/programs/zsh/zsh-autosuggestions.nix
parent42b833c43eb892fcdd8049c55c77a59f86682c77 (diff)
downloadnixpkgs-34b5dd453b13c2c09334e3def42416b5b2442a0a.tar
nixpkgs-34b5dd453b13c2c09334e3def42416b5b2442a0a.tar.gz
nixpkgs-34b5dd453b13c2c09334e3def42416b5b2442a0a.tar.bz2
nixpkgs-34b5dd453b13c2c09334e3def42416b5b2442a0a.tar.lz
nixpkgs-34b5dd453b13c2c09334e3def42416b5b2442a0a.tar.xz
nixpkgs-34b5dd453b13c2c09334e3def42416b5b2442a0a.tar.zst
nixpkgs-34b5dd453b13c2c09334e3def42416b5b2442a0a.zip
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.
Diffstat (limited to 'nixos/modules/programs/zsh/zsh-autosuggestions.nix')
-rw-r--r--nixos/modules/programs/zsh/zsh-autosuggestions.nix21
1 files changed, 11 insertions, 10 deletions
diff --git a/nixos/modules/programs/zsh/zsh-autosuggestions.nix b/nixos/modules/programs/zsh/zsh-autosuggestions.nix
index fee324cc732..2e53e907d54 100644
--- a/nixos/modules/programs/zsh/zsh-autosuggestions.nix
+++ b/nixos/modules/programs/zsh/zsh-autosuggestions.nix
@@ -22,17 +22,18 @@ in
     };
 
     strategy = mkOption {
-      type = types.enum [ "history" "match_prev_cmd" ];
-      default = "history";
+      type = types.listOf (types.enum [ "history" "completion" "match_prev_cmd" ]);
+      default = [ "history" ];
       description = ''
-        Set ZSH_AUTOSUGGEST_STRATEGY to choose the strategy for generating suggestions.
-        There are currently two to choose from:
+        `ZSH_AUTOSUGGEST_STRATEGY` is an array that specifies how suggestions should be generated.
+        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.
-          * match_prev_cmd: Chooses the most recent match whose preceding history item matches
-            the most recently executed command (more info). Note that this strategy won't work as
-            expected with ZSH options that don't preserve the history order such as
-            HIST_IGNORE_ALL_DUPS or HIST_EXPIRE_DUPS_FIRST.
+        - `history`: Chooses the most recent match from history.
+        - `completion`: Chooses a suggestion based on what tab-completion would suggest. (requires `zpty` module)
+        - `match_prev_cmd`: Like `history`, but chooses the most recent match whose preceding history item matches
+            the most recently executed command. Note that this strategy won't work as expected with ZSH options that
+            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
 
       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"}
 
       ${concatStringsSep "\n" (mapAttrsToList (key: value: ''export ${key}="${value}"'') cfg.extraConfig)}