1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-30 15:09:46 +01:00
home-manager/modules/programs/fzf.nix

174 lines
5 KiB
Nix
Raw Normal View History

2018-02-18 09:45:10 +01:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.fzf;
2020-02-02 00:39:17 +01:00
in {
imports = [
(mkRemovedOptionModule [ "programs" "fzf" "historyWidgetCommand" ]
"This option is no longer supported by fzf.")
];
2018-02-18 09:45:10 +01:00
options.programs.fzf = {
enable = mkEnableOption "fzf - a command-line fuzzy finder";
2021-01-14 05:25:53 +01:00
package = mkOption {
type = types.package;
default = pkgs.fzf;
defaultText = literalExpression "pkgs.fzf";
2021-01-14 05:25:53 +01:00
description = "Package providing the <command>fzf</command> tool.";
};
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 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" ];
description = ''
Extra command line options given to fzf by default.
'';
};
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 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 {}'" ];
description = ''
Command line options for the CTRL-T keybinding.
'';
};
changeDirWidgetCommand = mkOption {
type = types.nullOr types.str;
default = null;
2020-02-02 00:39:17 +01:00
example = "fd --type d";
description = ''
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'" ];
description = ''
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" ];
description = ''
Command line options for the CTRL-R keybinding.
'';
};
tmux = {
enableShellIntegration = mkEnableOption ''
setting <literal>FZF_TMUX=1</literal> which causes shell integration to use fzf-tmux
'';
shellIntegrationOptions = mkOption {
type = types.listOf types.str;
default = [ ];
example = literalExpression ''[ "-d 40%" ]'';
description = ''
If <option>programs.fzf.tmux.enableShellIntegration</option> is set to <literal>true</literal>,
shell integration will use these options for fzf-tmux.
See <command>fzf-tmux --help</command> for available options.
'';
};
};
2018-02-18 09:45:10 +01:00
enableBashIntegration = mkOption {
default = true;
type = types.bool;
description = ''
Whether to enable Bash integration.
'';
};
enableZshIntegration = mkOption {
default = true;
type = types.bool;
description = ''
Whether to enable Zsh integration.
'';
};
enableFishIntegration = mkOption {
default = true;
type = types.bool;
description = ''
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;
FZF_DEFAULT_OPTS = cfg.defaultOptions;
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
# 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.
programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 ''
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
. ${cfg.package}/share/fzf/completion.bash
. ${cfg.package}/share/fzf/key-bindings.bash
fi
'');
# 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.
programs.zsh.initExtra = mkIf cfg.enableZshIntegration (mkOrder 200 ''
if [[ $options[zle] = on ]]; then
. ${cfg.package}/share/fzf/completion.zsh
. ${cfg.package}/share/fzf/key-bindings.zsh
fi
'');
programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
source ${cfg.package}/share/fzf/key-bindings.fish && fzf_key_bindings
'';
2018-02-18 09:45:10 +01:00
};
}