9 cfg = config.programs.zsh.autosuggestions;
13 (lib.mkRenamedOptionModule
14 [ "programs" "zsh" "enableAutosuggestions" ]
15 [ "programs" "zsh" "autosuggestions" "enable" ]
19 options.programs.zsh.autosuggestions = {
21 enable = lib.mkEnableOption "zsh-autosuggestions";
23 highlightStyle = lib.mkOption {
25 default = "fg=8"; # https://github.com/zsh-users/zsh-autosuggestions/tree/v0.4.3#suggestion-highlight-style
26 description = "Highlight style for suggestions ({fore,back}ground color)";
30 strategy = lib.mkOption {
31 type = lib.types.listOf (
38 default = [ "history" ];
40 `ZSH_AUTOSUGGEST_STRATEGY` is an array that specifies how suggestions should be generated.
41 The strategies in the array are tried successively until a suggestion is found.
42 There are currently three built-in strategies to choose from:
44 - `history`: Chooses the most recent match from history.
45 - `completion`: Chooses a suggestion based on what tab-completion would suggest. (requires `zpty` module)
46 - `match_prev_cmd`: Like `history`, but chooses the most recent match whose preceding history item matches
47 the most recently executed command. Note that this strategy won't work as expected with ZSH options that
48 don't preserve the history order such as `HIST_IGNORE_ALL_DUPS` or `HIST_EXPIRE_DUPS_FIRST`.
52 async = lib.mkOption {
53 type = lib.types.bool;
55 description = "Whether to fetch suggestions asynchronously";
59 extraConfig = lib.mkOption {
60 type = lib.types.attrsOf lib.types.str;
62 description = "Attribute set with additional configuration values";
63 example = lib.literalExpression ''
65 "ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" = "20";
72 config = lib.mkIf cfg.enable {
74 programs.zsh.interactiveShellInit = ''
75 source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh
77 export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.highlightStyle}"
78 export ZSH_AUTOSUGGEST_STRATEGY=(${builtins.concatStringsSep " " cfg.strategy})
79 ${lib.optionalString (!cfg.async) "unset ZSH_AUTOSUGGEST_USE_ASYNC"}
81 ${builtins.concatStringsSep "\n" (
82 lib.mapAttrsToList (key: value: ''export ${key}="${value}"'') cfg.extraConfig