2018-02-18 08:45:10 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.fzf;
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2021-02-22 04:34:33 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "programs" "fzf" "historyWidgetCommand" ]
|
|
|
|
"This option is no longer supported by fzf.")
|
|
|
|
];
|
|
|
|
|
2018-02-18 08:45:10 +00:00
|
|
|
options.programs.fzf = {
|
|
|
|
enable = mkEnableOption "fzf - a command-line fuzzy finder";
|
|
|
|
|
2021-01-14 04:25:53 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.fzf;
|
|
|
|
defaultText = literalExample "pkgs.fzf";
|
|
|
|
description = "Package providing the <command>fzf</command> tool.";
|
|
|
|
};
|
|
|
|
|
2018-08-16 16:04:36 +00:00
|
|
|
defaultCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "fd --type f";
|
|
|
|
description = ''
|
|
|
|
The command that gets executed as the default source for fzf
|
|
|
|
when running.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-02-18 08:45:10 +00:00
|
|
|
defaultOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-01 23:39:17 +00:00
|
|
|
default = [ ];
|
2018-02-18 08:45:10 +00:00
|
|
|
example = [ "--height 40%" "--border" ];
|
|
|
|
description = ''
|
|
|
|
Extra command line options given to fzf by default.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-08-16 16:04:36 +00:00
|
|
|
fileWidgetCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "fd --type f";
|
|
|
|
description = ''
|
|
|
|
The command that gets executed as the source for fzf for the
|
|
|
|
CTRL-T keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-02-18 08:45:10 +00:00
|
|
|
fileWidgetOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-01 23:39:17 +00:00
|
|
|
default = [ ];
|
2018-02-18 08:45:10 +00:00
|
|
|
example = [ "--preview 'head {}'" ];
|
|
|
|
description = ''
|
|
|
|
Command line options for the CTRL-T keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-08-16 16:04:36 +00:00
|
|
|
changeDirWidgetCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2020-02-01 23:39:17 +00:00
|
|
|
example = "fd --type d";
|
2018-08-16 16:04:36 +00:00
|
|
|
description = ''
|
|
|
|
The command that gets executed as the source for fzf for the
|
|
|
|
ALT-C keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-02-18 08:45:10 +00:00
|
|
|
changeDirWidgetOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-01 23:39:17 +00:00
|
|
|
default = [ ];
|
2018-02-18 08:45:10 +00:00
|
|
|
example = [ "--preview 'tree -C {} | head -200'" ];
|
|
|
|
description = ''
|
|
|
|
Command line options for the ALT-C keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
historyWidgetOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-01 23:39:17 +00:00
|
|
|
default = [ ];
|
2018-02-18 08:45:10 +00:00
|
|
|
example = [ "--sort" "--exact" ];
|
|
|
|
description = ''
|
|
|
|
Command line options for the CTRL-R keybinding.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableBashIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Bash integration.
|
|
|
|
'';
|
|
|
|
};
|
2018-03-12 22:29:46 +00:00
|
|
|
|
|
|
|
enableZshIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Zsh integration.
|
|
|
|
'';
|
|
|
|
};
|
2020-03-06 11:28:13 +00:00
|
|
|
|
|
|
|
enableFishIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Fish integration.
|
|
|
|
'';
|
|
|
|
};
|
2018-02-18 08:45:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-01-14 04:25:53 +00:00
|
|
|
home.packages = [ cfg.package ];
|
2018-02-18 08:45:10 +00:00
|
|
|
|
2020-02-01 23:39:17 +00: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;
|
|
|
|
FZF_DEFAULT_OPTS = cfg.defaultOptions;
|
|
|
|
});
|
2018-02-18 08:45:10 +00:00
|
|
|
|
|
|
|
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
|
2018-10-29 23:09:20 +00:00
|
|
|
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
|
|
|
|
. ${pkgs.fzf}/share/fzf/completion.bash
|
|
|
|
. ${pkgs.fzf}/share/fzf/key-bindings.bash
|
|
|
|
fi
|
2018-02-18 08:45:10 +00:00
|
|
|
'';
|
2018-03-12 22:29:46 +00:00
|
|
|
|
|
|
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
|
2018-10-29 23:09:20 +00:00
|
|
|
if [[ $options[zle] = on ]]; then
|
|
|
|
. ${pkgs.fzf}/share/fzf/completion.zsh
|
|
|
|
. ${pkgs.fzf}/share/fzf/key-bindings.zsh
|
|
|
|
fi
|
2018-03-12 22:29:46 +00:00
|
|
|
'';
|
2020-03-06 11:28:13 +00:00
|
|
|
|
|
|
|
programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
|
|
|
|
source ${pkgs.fzf}/share/fzf/key-bindings.fish && fzf_key_bindings
|
|
|
|
'';
|
2018-02-18 08:45:10 +00:00
|
|
|
};
|
|
|
|
}
|