2018-06-10 23:08:50 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.zsh.autosuggestions;
|
|
|
|
in
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "programs" "zsh" "enableAutosuggestions" ] [ "programs" "zsh" "autosuggestions" "enable" ])
|
|
|
|
];
|
|
|
|
|
2018-06-10 23:08:50 +02:00
|
|
|
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
|
|
|
|
description = "Highlight style for suggestions ({fore,back}ground color)";
|
|
|
|
example = "fg=cyan";
|
|
|
|
};
|
|
|
|
|
|
|
|
strategy = mkOption {
|
2018-12-10 16:10:19 +01:00
|
|
|
type = types.enum [ "history" "match_prev_cmd" ];
|
|
|
|
default = "history";
|
2018-06-10 23:08:50 +02:00
|
|
|
description = ''
|
|
|
|
Set ZSH_AUTOSUGGEST_STRATEGY to choose the strategy for generating suggestions.
|
|
|
|
There are currently two to choose from:
|
|
|
|
|
2018-12-10 16:10:19 +01:00
|
|
|
* history: Chooses the most recent match.
|
2018-06-10 23:08:50 +02:00
|
|
|
* 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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-10-25 11:33:35 +02:00
|
|
|
async = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to fetch suggestions asynchronously";
|
|
|
|
example = false;
|
|
|
|
};
|
|
|
|
|
2018-06-10 23:08:50 +02:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = with types; attrsOf str;
|
|
|
|
default = {};
|
|
|
|
description = "Attribute set with additional configuration values";
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
2018-06-10 23:08:50 +02: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}"
|
2018-12-10 16:10:19 +01:00
|
|
|
export ZSH_AUTOSUGGEST_STRATEGY=("${cfg.strategy}")
|
2021-10-25 11:33:35 +02:00
|
|
|
${optionalString (!cfg.async) "unset ZSH_AUTOSUGGEST_USE_ASYNC"}
|
2018-06-10 23:08:50 +02:00
|
|
|
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (key: value: ''export ${key}="${value}"'') cfg.extraConfig)}
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|