diff --git a/modules/misc/news.nix b/modules/misc/news.nix index c9edc8798..a0718b190 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -580,6 +580,13 @@ in A new module is available: 'services.unclutter' ''; } + + { + time = "2018-03-07T21:38:27+00:00"; + message = '' + A new module is available: 'programs.fzf'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index de5749ff7..eca0678d4 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -30,6 +30,7 @@ let ./programs/emacs.nix ./programs/feh.nix ./programs/firefox.nix + ./programs/fzf.nix ./programs/git.nix ./programs/gnome-terminal.nix ./programs/home-manager.nix diff --git a/modules/programs/fzf.nix b/modules/programs/fzf.nix new file mode 100644 index 000000000..7949f7f8f --- /dev/null +++ b/modules/programs/fzf.nix @@ -0,0 +1,78 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.fzf; + +in + +{ + options.programs.fzf = { + enable = mkEnableOption "fzf - a command-line fuzzy finder"; + + defaultOptions = mkOption { + type = types.listOf types.str; + default = []; + example = [ "--height 40%" "--border" ]; + description = '' + Extra command line options given to fzf by default. + ''; + }; + + fileWidgetOptions = mkOption { + type = types.listOf types.str; + default = []; + example = [ "--preview 'head {}'" ]; + description = '' + Command line options for the CTRL-T keybinding. + ''; + }; + + changeDirWidgetOptions = mkOption { + type = types.listOf types.str; + default = []; + example = [ "--preview 'tree -C {} | head -200'" ]; + description = '' + Command line options for the ALT-C keybinding. + ''; + }; + + historyWidgetOptions = mkOption { + type = types.listOf types.str; + default = []; + 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. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.fzf ]; + + home.sessionVariables = + mapAttrs (n: v: toString v) ( + filterAttrs (n: v: v != []) { + FZF_ALT_C_OPTS = cfg.changeDirWidgetOptions; + FZF_CTRL_R_OPTS = cfg.historyWidgetOptions; + FZF_CTRL_T_OPTS = cfg.fileWidgetOptions; + FZF_DEFAULT_OPTS = cfg.defaultOptions; + } + ); + + programs.bash.initExtra = mkIf cfg.enableBashIntegration '' + . ${pkgs.fzf}/share/fzf/completion.bash + . ${pkgs.fzf}/share/fzf/key-bindings.bash + ''; + }; +}