2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.zsh.autosuggestions;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "programs" "zsh" "enableAutosuggestions" ] [ "programs" "zsh" "autosuggestions" "enable" ])
|
|
|
|
];
|
|
|
|
|
|
|
|
options.programs.zsh.autosuggestions = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "zsh-autosuggestions";
|
|
|
|
|
|
|
|
highlightStyle = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "fg=8"; # https://github.com/zsh-users/zsh-autosuggestions/tree/v0.4.3#suggestion-highlight-style
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Highlight style for suggestions ({fore,back}ground color)";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = "fg=cyan";
|
|
|
|
};
|
|
|
|
|
|
|
|
strategy = mkOption {
|
2022-03-10 19:12:11 +00:00
|
|
|
type = types.listOf (types.enum [ "history" "completion" "match_prev_cmd" ]);
|
|
|
|
default = [ "history" ];
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
`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:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-03-10 19:12:11 +00:00
|
|
|
- `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`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
async = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to fetch suggestions asynchronously";
|
2021-12-06 16:07:01 +00:00
|
|
|
example = false;
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = with types; attrsOf str;
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Attribute set with additional configuration values";
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
"ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" = "20";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
programs.zsh.interactiveShellInit = ''
|
|
|
|
source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh
|
|
|
|
|
|
|
|
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.highlightStyle}"
|
2022-03-10 19:12:11 +00:00
|
|
|
export ZSH_AUTOSUGGEST_STRATEGY=(${concatStringsSep " " cfg.strategy})
|
2021-12-06 16:07:01 +00:00
|
|
|
${optionalString (!cfg.async) "unset ZSH_AUTOSUGGEST_USE_ASYNC"}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (key: value: ''export ${key}="${value}"'') cfg.extraConfig)}
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|