2018-02-18 09:45:10 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.fzf;
|
|
|
|
|
2022-11-21 16:35:18 +01:00
|
|
|
renderedColors = colors:
|
|
|
|
concatStringsSep ","
|
|
|
|
(mapAttrsToList (name: value: "${name}:${value}") colors);
|
|
|
|
|
2024-04-09 08:57:29 +02:00
|
|
|
hasShellIntegrationEmbedded = lib.versionAtLeast cfg.package.version "0.48.0";
|
|
|
|
|
|
|
|
bashIntegration = if hasShellIntegrationEmbedded then ''
|
|
|
|
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
|
|
|
|
eval "$(${getExe cfg.package} --bash)"
|
|
|
|
fi
|
|
|
|
'' else ''
|
|
|
|
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
|
|
|
|
. ${cfg.package}/share/fzf/completion.bash
|
|
|
|
. ${cfg.package}/share/fzf/key-bindings.bash
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
zshIntegration = if hasShellIntegrationEmbedded then ''
|
|
|
|
if [[ $options[zle] = on ]]; then
|
|
|
|
eval "$(${getExe cfg.package} --zsh)"
|
|
|
|
fi
|
|
|
|
'' else ''
|
|
|
|
if [[ $options[zle] = on ]]; then
|
|
|
|
. ${cfg.package}/share/fzf/completion.zsh
|
|
|
|
. ${cfg.package}/share/fzf/key-bindings.zsh
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
fishIntegration = if hasShellIntegrationEmbedded then ''
|
|
|
|
${getExe cfg.package} --fish | source
|
|
|
|
'' else ''
|
|
|
|
source ${cfg.package}/share/fzf/key-bindings.fish && fzf_key_bindings
|
|
|
|
'';
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2021-02-22 05:34:33 +01:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "programs" "fzf" "historyWidgetCommand" ]
|
|
|
|
"This option is no longer supported by fzf.")
|
|
|
|
];
|
|
|
|
|
2018-02-18 09:45:10 +01:00
|
|
|
options.programs.fzf = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "fzf - a command-line fuzzy finder";
|
2018-02-18 09:45:10 +01:00
|
|
|
|
2021-01-14 05:25:53 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.fzf;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.fzf";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Package providing the {command}`fzf` tool.";
|
2021-01-14 05:25:53 +01:00
|
|
|
};
|
|
|
|
|
2018-08-16 18:04:36 +02:00
|
|
|
defaultCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "fd --type f";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-08-16 18:04:36 +02:00
|
|
|
The command that gets executed as the default source for fzf
|
|
|
|
when running.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-02-18 09:45:10 +01:00
|
|
|
defaultOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2018-02-18 09:45:10 +01:00
|
|
|
example = [ "--height 40%" "--border" ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-02-18 09:45:10 +01:00
|
|
|
Extra command line options given to fzf by default.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-08-16 18:04:36 +02:00
|
|
|
fileWidgetCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "fd --type f";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-08-16 18:04:36 +02:00
|
|
|
The command that gets executed as the source for fzf for the
|
|
|
|
CTRL-T keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-02-18 09:45:10 +01:00
|
|
|
fileWidgetOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2018-02-18 09:45:10 +01:00
|
|
|
example = [ "--preview 'head {}'" ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-02-18 09:45:10 +01:00
|
|
|
Command line options for the CTRL-T keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-08-16 18:04:36 +02:00
|
|
|
changeDirWidgetCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2020-02-02 00:39:17 +01:00
|
|
|
example = "fd --type d";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-08-16 18:04:36 +02:00
|
|
|
The command that gets executed as the source for fzf for the
|
|
|
|
ALT-C keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-02-18 09:45:10 +01:00
|
|
|
changeDirWidgetOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2018-02-18 09:45:10 +01:00
|
|
|
example = [ "--preview 'tree -C {} | head -200'" ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-02-18 09:45:10 +01:00
|
|
|
Command line options for the ALT-C keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
historyWidgetOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2018-02-18 09:45:10 +01:00
|
|
|
example = [ "--sort" "--exact" ];
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-02-18 09:45:10 +01:00
|
|
|
Command line options for the CTRL-R keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-11-21 16:35:18 +01:00
|
|
|
colors = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
bg = "#1e1e1e";
|
|
|
|
"bg+" = "#1e1e1e";
|
|
|
|
fg = "#d4d4d4";
|
|
|
|
"fg+" = "#d4d4d4";
|
|
|
|
}
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Color scheme options added to `FZF_DEFAULT_OPTS`. See
|
|
|
|
<https://github.com/junegunn/fzf/wiki/Color-schemes>
|
2022-11-21 16:35:18 +01:00
|
|
|
for documentation.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-05-02 00:10:41 +02:00
|
|
|
tmux = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enableShellIntegration = mkEnableOption ''
|
2023-07-01 01:30:13 +02:00
|
|
|
setting `FZF_TMUX=1` which causes shell integration to use fzf-tmux
|
2023-07-02 01:45:18 +02:00
|
|
|
'';
|
2021-05-02 00:10:41 +02:00
|
|
|
|
|
|
|
shellIntegrationOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''[ "-d 40%" ]'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
If {option}`programs.fzf.tmux.enableShellIntegration` is set to `true`,
|
2021-05-02 00:10:41 +02:00
|
|
|
shell integration will use these options for fzf-tmux.
|
2023-07-01 01:30:13 +02:00
|
|
|
See {command}`fzf-tmux --help` for available options.
|
2021-05-02 00:10:41 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-02-18 09:45:10 +01:00
|
|
|
enableBashIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-02-18 09:45:10 +01:00
|
|
|
Whether to enable Bash integration.
|
|
|
|
'';
|
|
|
|
};
|
2018-03-12 23:29:46 +01:00
|
|
|
|
|
|
|
enableZshIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-03-12 23:29:46 +01:00
|
|
|
Whether to enable Zsh integration.
|
|
|
|
'';
|
|
|
|
};
|
2020-03-06 12:28:13 +01:00
|
|
|
|
|
|
|
enableFishIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-03-06 12:28:13 +01:00
|
|
|
Whether to enable Fish integration.
|
|
|
|
'';
|
|
|
|
};
|
2018-02-18 09:45:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-01-14 05:25:53 +01:00
|
|
|
home.packages = [ cfg.package ];
|
2018-02-18 09:45:10 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
home.sessionVariables = mapAttrs (n: v: toString v)
|
|
|
|
(filterAttrs (n: v: v != [ ] && v != null) {
|
|
|
|
FZF_ALT_C_COMMAND = cfg.changeDirWidgetCommand;
|
|
|
|
FZF_ALT_C_OPTS = cfg.changeDirWidgetOptions;
|
|
|
|
FZF_CTRL_R_OPTS = cfg.historyWidgetOptions;
|
|
|
|
FZF_CTRL_T_COMMAND = cfg.fileWidgetCommand;
|
|
|
|
FZF_CTRL_T_OPTS = cfg.fileWidgetOptions;
|
|
|
|
FZF_DEFAULT_COMMAND = cfg.defaultCommand;
|
2022-11-21 16:35:18 +01:00
|
|
|
FZF_DEFAULT_OPTS = cfg.defaultOptions
|
|
|
|
++ lib.optionals (cfg.colors != { })
|
|
|
|
[ "--color ${renderedColors cfg.colors}" ];
|
2021-05-02 00:10:41 +02:00
|
|
|
FZF_TMUX = if cfg.tmux.enableShellIntegration then "1" else null;
|
|
|
|
FZF_TMUX_OPTS = cfg.tmux.shellIntegrationOptions;
|
2020-02-02 00:39:17 +01:00
|
|
|
});
|
2018-02-18 09:45:10 +01:00
|
|
|
|
2021-10-06 00:20:32 +02:00
|
|
|
# Note, since fzf unconditionally binds C-r we use `mkOrder` to make the
|
|
|
|
# initialization show up a bit earlier. This is to make initialization of
|
|
|
|
# other history managers, like mcfly or atuin, take precedence.
|
2024-04-09 08:57:29 +02:00
|
|
|
programs.bash.initExtra =
|
|
|
|
mkIf cfg.enableBashIntegration (mkOrder 200 bashIntegration);
|
2018-03-12 23:29:46 +01:00
|
|
|
|
2021-10-06 00:20:32 +02:00
|
|
|
# Note, since fzf unconditionally binds C-r we use `mkOrder` to make the
|
|
|
|
# initialization show up a bit earlier. This is to make initialization of
|
|
|
|
# other history managers, like mcfly or atuin, take precedence.
|
2024-04-09 08:57:29 +02:00
|
|
|
programs.zsh.initExtra =
|
|
|
|
mkIf cfg.enableZshIntegration (mkOrder 200 zshIntegration);
|
|
|
|
|
|
|
|
programs.fish.interactiveShellInit =
|
|
|
|
mkIf cfg.enableFishIntegration (mkOrder 200 fishIntegration);
|
2018-02-18 09:45:10 +01:00
|
|
|
};
|
|
|
|
}
|