1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.programs.zsh.autosuggestions;
7in
8{
9 options.programs.zsh.autosuggestions = {
10
11 enable = mkEnableOption "zsh-autosuggestions";
12
13 highlightStyle = mkOption {
14 type = types.str;
15 default = "fg=8"; # https://github.com/zsh-users/zsh-autosuggestions/tree/v0.4.3#suggestion-highlight-style
16 description = "Highlight style for suggestions ({fore,back}ground color)";
17 example = "fg=cyan";
18 };
19
20 strategy = mkOption {
21 type = types.enum [ "default" "match_prev_cmd" ];
22 default = "default";
23 description = ''
24 Set ZSH_AUTOSUGGEST_STRATEGY to choose the strategy for generating suggestions.
25 There are currently two to choose from:
26
27 * default: Chooses the most recent match.
28 * match_prev_cmd: Chooses the most recent match whose preceding history item matches
29 the most recently executed command (more info). Note that this strategy won't work as
30 expected with ZSH options that don't preserve the history order such as
31 HIST_IGNORE_ALL_DUPS or HIST_EXPIRE_DUPS_FIRST.
32 '';
33 };
34
35 extraConfig = mkOption {
36 type = with types; attrsOf str;
37 default = {};
38 description = "Attribute set with additional configuration values";
39 example = literalExample ''
40 {
41 "ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" = "20";
42 }
43 '';
44 };
45
46 };
47
48 config = mkIf cfg.enable {
49
50 programs.zsh.interactiveShellInit = ''
51 source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh
52
53 export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.highlightStyle}"
54 export ZSH_AUTOSUGGEST_STRATEGY="${cfg.strategy}"
55
56 ${concatStringsSep "\n" (mapAttrsToList (key: value: ''export ${key}="${value}"'') cfg.extraConfig)}
57 '';
58
59 };
60}