|
|
@ -11,7 +11,7 @@ local config = require "fzf-lua.config"
|
|
|
|
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
|
|
|
|
local get_grep_cmd = function(opts)
|
|
|
|
local get_grep_cmd = function(opts, search_query, no_esc)
|
|
|
|
|
|
|
|
|
|
|
|
local command = nil
|
|
|
|
local command = nil
|
|
|
|
if opts.cmd and #opts.cmd > 0 then
|
|
|
|
if opts.cmd and #opts.cmd > 0 then
|
|
|
@ -30,11 +30,12 @@ local get_grep_cmd = function(opts)
|
|
|
|
search_path = vim.fn.shellescape(opts.cwd)
|
|
|
|
search_path = vim.fn.shellescape(opts.cwd)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return string.format("%s -- %s %s", command,
|
|
|
|
if search_query == nil then search_query = ''
|
|
|
|
utils._if(opts.last_search and #opts.last_search>0,
|
|
|
|
elseif not no_esc then
|
|
|
|
vim.fn.shellescape(opts.last_search), "{q}"),
|
|
|
|
search_query = vim.fn.shellescape(utils.rg_escape(search_query))
|
|
|
|
search_path
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return string.format("%s -- %s %s", command, search_query, search_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
M.grep = function(opts)
|
|
|
|
M.grep = function(opts)
|
|
|
@ -46,28 +47,26 @@ M.grep = function(opts)
|
|
|
|
"rg_opts", "grep_opts",
|
|
|
|
"rg_opts", "grep_opts",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if opts.search and #opts.search>0 then
|
|
|
|
if opts.continue_last_search or opts.repeat_last_search then
|
|
|
|
opts.search = utils.rg_escape(opts.search)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if opts.repeat_last_search == true then
|
|
|
|
|
|
|
|
opts.search = config.grep.last_search
|
|
|
|
opts.search = config.grep.last_search
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- save the next search as last_search so we
|
|
|
|
|
|
|
|
-- let the caller have an option to run the
|
|
|
|
-- if user did not provide a search term
|
|
|
|
-- same search again
|
|
|
|
-- provide an input prompt
|
|
|
|
if not opts.search or #opts.search == 0 then
|
|
|
|
if not opts.search or #opts.search == 0 then
|
|
|
|
config.grep.last_search = vim.fn.input(opts.input_prompt)
|
|
|
|
opts.search = vim.fn.input(opts.input_prompt)
|
|
|
|
else
|
|
|
|
|
|
|
|
config.grep.last_search = opts.search
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
opts.last_search = config.grep.last_search
|
|
|
|
|
|
|
|
if not opts.last_search or #opts.last_search == 0 then
|
|
|
|
if not opts.search or #opts.search == 0 then
|
|
|
|
utils.info("Please provider valid search string")
|
|
|
|
utils.info("Please provide a valid search string")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local command = get_grep_cmd(opts)
|
|
|
|
-- save the search query so the use can
|
|
|
|
|
|
|
|
-- call the same search again
|
|
|
|
|
|
|
|
config.grep.last_search = opts.search
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local command = get_grep_cmd(opts, opts.search)
|
|
|
|
|
|
|
|
|
|
|
|
opts.fzf_fn = fzf_helpers.cmd_line_transformer(
|
|
|
|
opts.fzf_fn = fzf_helpers.cmd_line_transformer(
|
|
|
|
command,
|
|
|
|
command,
|
|
|
@ -94,9 +93,35 @@ M.grep = function(opts)
|
|
|
|
]]
|
|
|
|
]]
|
|
|
|
opts.preview_offset = "+{3}-/2"
|
|
|
|
opts.preview_offset = "+{3}-/2"
|
|
|
|
core.fzf_files(opts)
|
|
|
|
core.fzf_files(opts)
|
|
|
|
|
|
|
|
opts.search = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
M.live_grep_sk = function(opts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- "'{}'" opens sk with an empty search_query showing all files
|
|
|
|
|
|
|
|
-- "{}" opens sk without executing an empty string query
|
|
|
|
|
|
|
|
-- the problem is the latter doesn't support escaped chars
|
|
|
|
|
|
|
|
-- TODO: how to open without a query with special char support
|
|
|
|
|
|
|
|
local sk_args = get_grep_cmd(opts , "'{}'", true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts.cli_args = "--delimiter='[: ]' " ..
|
|
|
|
|
|
|
|
string.format("--cmd-prompt='%s' -i -c %s",
|
|
|
|
|
|
|
|
opts.prompt,
|
|
|
|
|
|
|
|
vim.fn.shellescape(sk_args))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts.git_icons = false
|
|
|
|
|
|
|
|
opts.file_icons = false
|
|
|
|
|
|
|
|
opts.filespec = '{1}'
|
|
|
|
|
|
|
|
opts.preview_offset = "+{2}-/2"
|
|
|
|
|
|
|
|
opts.preview_args = "--highlight-line={2}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts.fzf_fn = nil --function(_) end
|
|
|
|
|
|
|
|
core.fzf_files(opts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opts.search = nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
M.live_grep = function(opts)
|
|
|
|
M.live_grep = function(opts)
|
|
|
|
|
|
|
|
|
|
|
|
opts = config.getopts(opts, config.grep, {
|
|
|
|
opts = config.getopts(opts, config.grep, {
|
|
|
@ -106,41 +131,33 @@ M.live_grep = function(opts)
|
|
|
|
"rg_opts", "grep_opts",
|
|
|
|
"rg_opts", "grep_opts",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if opts.continue_last_search or opts.repeat_last_search then
|
|
|
|
|
|
|
|
opts.search = config.grep.last_search
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if opts.search and #opts.search>0 then
|
|
|
|
if opts.search and #opts.search>0 then
|
|
|
|
opts.search = utils.rg_escape(opts.search)
|
|
|
|
-- save the search query so the use can
|
|
|
|
|
|
|
|
-- call the same search again
|
|
|
|
|
|
|
|
config.grep.last_search = opts.search
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- resetting last_search will return
|
|
|
|
-- HACK: support skim (rust version of fzf)
|
|
|
|
-- {q} placeholder in our command
|
|
|
|
opts.fzf_bin = opts.fzf_bin or config.fzf_bin
|
|
|
|
opts.last_search = opts.search
|
|
|
|
if opts.fzf_bin and opts.fzf_bin:find('sk')~=nil then
|
|
|
|
local initial_command = get_grep_cmd(opts)
|
|
|
|
return M.live_grep_sk(opts)
|
|
|
|
opts.last_search = nil
|
|
|
|
end
|
|
|
|
local reload_command = get_grep_cmd(opts) .. " || true"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--[[ local fzf_binds = utils.tbl_deep_clone(config.fzf_binds)
|
|
|
|
-- use {q} as a placeholder for fzf
|
|
|
|
table.insert(fzf_binds, string.format("change:reload:%s", reload_command))
|
|
|
|
local initial_command = get_grep_cmd(opts, opts.search)
|
|
|
|
opts.fzf_binds = vim.fn.shellescape(table.concat(fzf_binds, ',')) ]]
|
|
|
|
local reload_command = get_grep_cmd(opts, "{q}", true) .. " || true"
|
|
|
|
|
|
|
|
|
|
|
|
opts.cli_args = "--delimiter='[: ]' " ..
|
|
|
|
opts.cli_args = "--delimiter='[: ]' " ..
|
|
|
|
string.format("--phony --query=%s --bind=%s",
|
|
|
|
string.format("--phony --query=%s --bind=%s",
|
|
|
|
utils._if(opts.search and #opts.search>0, opts.search, [['']]),
|
|
|
|
utils._if(opts.search and #opts.search>0,
|
|
|
|
|
|
|
|
vim.fn.shellescape(utils.rg_escape(opts.search)),
|
|
|
|
|
|
|
|
[['']]),
|
|
|
|
vim.fn.shellescape(string.format("change:reload:%s", reload_command)))
|
|
|
|
vim.fn.shellescape(string.format("change:reload:%s", reload_command)))
|
|
|
|
|
|
|
|
|
|
|
|
opts.preview_args = "--highlight-line={3}" -- bat higlight
|
|
|
|
|
|
|
|
--[[
|
|
|
|
|
|
|
|
# Preview with bat, matching line in the middle of the window below
|
|
|
|
|
|
|
|
# the fixed header of the top 3 lines
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ~3 Top 3 lines as the fixed header
|
|
|
|
|
|
|
|
# +{2} Base scroll offset extracted from the second field
|
|
|
|
|
|
|
|
# +3 Extra offset to compensate for the 3-line header
|
|
|
|
|
|
|
|
# /2 Put in the middle of the preview area
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
'--preview-window '~3:+{2}+3/2''
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
opts.preview_offset = "+{3}-/2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TODO:
|
|
|
|
-- TODO:
|
|
|
|
-- this is not getting called past the initial command
|
|
|
|
-- this is not getting called past the initial command
|
|
|
|
-- until we fix that we cannot use icons as they interfere
|
|
|
|
-- until we fix that we cannot use icons as they interfere
|
|
|
@ -158,11 +175,12 @@ M.live_grep = function(opts)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
core.fzf_files(opts)
|
|
|
|
core.fzf_files(opts)
|
|
|
|
|
|
|
|
opts.search = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
M.grep_last = function(opts)
|
|
|
|
M.grep_last = function(opts)
|
|
|
|
if not opts then opts = {} end
|
|
|
|
if not opts then opts = {} end
|
|
|
|
opts.repeat_last_search = true
|
|
|
|
opts.continue_last_search = true
|
|
|
|
return M.grep(opts)
|
|
|
|
return M.grep(opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|