nix-community.nixvim/plugins/utils/fzf-lua.nix

131 lines
3 KiB
Nix
Raw Normal View History

2023-12-08 16:34:34 +07:00
{
lib,
helpers,
config,
pkgs,
...
}:
2024-05-05 19:39:35 +02:00
with lib;
let
2023-12-08 16:34:34 +07:00
settingsOptions = {
fzf_bin = helpers.mkNullOrStr ''
The path to the `fzf` binary to use.
Example: `"skim"`
'';
};
settingsExample = {
winopts = {
height = 0.4;
width = 0.93;
row = 0.99;
col = 0.3;
};
files = {
find_opts.__raw = "[[-type f -not -path '*.git/objects*' -not -path '*.env*']]";
prompt = "Files ";
multiprocess = true;
file_icons = true;
color_icons = true;
};
};
in
2024-05-05 19:39:35 +02:00
helpers.neovim-plugin.mkNeovimPlugin config {
name = "fzf-lua";
defaultPackage = pkgs.vimPlugins.fzf-lua;
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
extraPackages = [ pkgs.fzf ];
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
maintainers = [ maintainers.GaetanLepage ];
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
inherit settingsOptions settingsExample;
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
extraOptions = {
fzfPackage = helpers.mkPackageOption {
name = "fzf";
2024-05-05 19:39:35 +02:00
default = pkgs.fzf;
example = pkgs.skim;
};
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
iconsEnabled = mkOption {
type = types.bool;
description = "Toggle icon support. Installs nvim-web-devicons.";
default = true;
};
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
profile = helpers.defaultNullOpts.mkEnumFirstDefault [
"default"
"fzf-native"
"fzf-tmux"
"fzf-vim"
"max-perf"
"telescope"
"skim"
] "Preconfigured profile to use";
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
keymaps = mkOption {
type =
with types;
attrsOf (
either str (submodule {
2023-12-08 16:34:34 +07:00
options = {
2024-05-05 19:39:35 +02:00
action = mkOption {
type = types.str;
description = "The `fzf-lua` action to run";
example = "git_files";
};
settings = helpers.mkSettingsOption {
options = settingsOptions;
description = "`fzf-lua` settings for this command.";
example = settingsExample;
};
mode = helpers.keymaps.mkModeOption "n";
options = helpers.keymaps.mapConfigOptions;
2023-12-08 16:34:34 +07:00
};
2024-05-05 19:39:35 +02:00
})
);
description = "Keymaps for Fzf-Lua.";
default = { };
example = {
"<leader>fg" = "live_grep";
"<C-p>" = {
action = "git_files";
settings = {
previewers.cat.cmd = "${pkgs.coreutils}/bin/cat";
winopts.height = 0.5;
};
options = {
silent = true;
desc = "Fzf-Lua Git Files";
2023-12-08 16:34:34 +07:00
};
};
};
};
2024-05-05 19:39:35 +02:00
};
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
extraConfig = cfg: {
extraPlugins = optional cfg.iconsEnabled pkgs.vimPlugins.nvim-web-devicons;
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
extraPackages = optional (cfg.fzfPackage != null) cfg.fzfPackage;
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
plugins.fzf-lua.settings.__unkeyed_profile = cfg.profile;
2023-12-08 16:34:34 +07:00
2024-05-05 19:39:35 +02:00
keymaps = mapAttrsToList (
key: mapping:
let
actionStr =
if isString mapping then
"${mapping}()"
else
"${mapping.action}(${helpers.toLuaObject mapping.settings})";
in
{
inherit key;
mode = mapping.mode or "n";
action.__raw = "function() require('fzf-lua').${actionStr} end";
options = mapping.options or { };
}
) cfg.keymaps;
};
}