From 36f84404fa1477c2a8250aa3df407047babe1e90 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Tue, 8 Mar 2022 22:54:56 -0800 Subject: [PATCH] tags_grep: respect 'tags.rg|grep_opts' --- lua/fzf-lua/providers/tags.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lua/fzf-lua/providers/tags.lua b/lua/fzf-lua/providers/tags.lua index 5a651c0..41fdaa3 100644 --- a/lua/fzf-lua/providers/tags.lua +++ b/lua/fzf-lua/providers/tags.lua @@ -22,11 +22,12 @@ function M.set_last_search(_, query, no_esc) end end -local function get_tags_cmd(opts, flags) - local query = nil - local cmd = "grep" +local function get_tags_cmd(opts) + local cmd, query = nil, nil if vim.fn.executable("rg") == 1 then - cmd = "rg" + cmd = ("%s %s"):format("rg", opts.rg_opts or '') + else + cmd = ("%s %s"):format("grep", opts.grep_opts or '') end if opts.search and #opts.search>0 then query = libuv.shellescape(opts.no_esc and opts.search or @@ -36,7 +37,7 @@ local function get_tags_cmd(opts, flags) else query = "-v '^!_TAG_'" end - return ("%s %s %s %s"):format(cmd, flags or '', query, + return ("%s %s %s"):format(cmd, query, vim.fn.shellescape(opts._ctags_file)) end @@ -63,7 +64,11 @@ local function tags(opts) if opts.line_field_index == nil then -- if caller did not specify the line field index -- grep the first tag with '-m 1' and test for line presence - local cmd = get_tags_cmd({ _ctags_file = opts._ctags_file }, "-m 1") + local cmd = get_tags_cmd({ + rg_opts = "-m 1", + grep_opts = "-m 1", + _ctags_file = opts._ctags_file + }) local ok, lines, err = pcall(utils.io_systemlist, cmd) if ok and err == 0 and lines and not vim.tbl_isempty(lines) then local tag, line = make_entry.tag(opts, lines[1])