ooknet/outputs/pkgs/ook-vim/modules/plugins/telescope/config.nix

55 lines
1.8 KiB
Nix

{
config,
lib,
inputs,
...
}: let
inherit (lib) mkIf mkOption;
inherit (lib.types) bool;
inherit (inputs.nvf.lib.nvim.dag) entryAfter;
cfg = config.vim.telescope;
in {
options.vim.telescope = {
autostart = mkOption {
type = bool;
default = false;
description = "Auto start telescope when opening neovim unless opening a file";
};
};
config = mkIf cfg.autostart {
vim.luaConfigRC.telescope-autostart =
entryAfter ["pluginConfigs"]
#lua
''
local find_files_hijack_netrw = vim.api.nvim_create_augroup("find_files_hijack_netrw", { clear = true })
-- clear FileExplorer appropriately to prevent netrw from launching on folders
-- netrw may or may not be loaded before telescope-find-files
-- conceptual credits to nvim-tree and telescope-file-browser
vim.api.nvim_create_autocmd("VimEnter", {
pattern = "*",
once = true,
callback = function()
pcall(vim.api.nvim_clear_autocmds, { group = "FileExplorer" })
end,
})
vim.api.nvim_create_autocmd("BufEnter", {
group = find_files_hijack_netrw,
pattern = "*",
callback = function()
vim.schedule(function()
-- Early return if netrw or not a directory
if vim.bo[0].filetype == "netrw" or vim.fn.isdirectory(vim.fn.expand("%:p")) == 0 then
return
end
vim.api.nvim_buf_set_option(0, "bufhidden", "wipe")
require("telescope.builtin").find_files({
cwd = vim.fn.expand("%:p:h"),
})
end)
end,
})
'';
};
}