From 7d1bff97c600c7fd5457f7f10206484f128d687f Mon Sep 17 00:00:00 2001 From: Kay Gosho Date: Sat, 25 Jun 2022 12:17:20 +0900 Subject: [PATCH] improve with https://github.com/ibhagwan/fzf-lua/issues/459#issuecomment-1165883084 --- home/.config/nvim/init.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua index 0acb1852..2e3dc37c 100644 --- a/home/.config/nvim/init.lua +++ b/home/.config/nvim/init.lua @@ -49,13 +49,23 @@ vim.api.nvim_create_autocmd({ "BufReadPost" }, { end, }) -local function git_files_cwd_aware() - local relative_path = util.get_working_path_from_git_root() - if relative_path == "" then - require("fzf-lua").git_files() - else - require("fzf-lua").git_files({ fzf_opts = { ["--query"] = relative_path } }) +-- The reason I added 'opts' as a paraameter is so you can +-- call this function with your own parameters / customizations +-- for example: 'git_files_cwd_aware({ cwd = })' +local function git_files_cwd_aware(opts) + opts = opts or {} + local fzf_lua = require("fzf-lua") + -- git_root() will warn us if we're not inside a git repo + -- so we don't have to add another warning here, if + -- you want to avoid the error message change it to: + -- local git_root = fzf_lua.path.git_root(opts, true) + local git_root = fzf_lua.path.git_root(opts) + if not git_root then + return end + local relative = fzf_lua.path.relative(vim.loop.cwd(), git_root) + opts.fzf_opts = { ["--query"] = git_root ~= relative and relative .. "/" or nil } + return fzf_lua.git_files(opts) end vim.keymap.set("", "", "")