added cwd to search headers, added headers to live_grep

main
bhagwan 3 years ago
parent eaf465f9e9
commit eb19fb51ac

@ -108,7 +108,7 @@ M.build_fzf_cli = function(opts, debug_print)
[[ %s %s --layout=%s --bind=%s --prompt=%s]] ..
[[ --preview-window=%s%s --preview=%s]] ..
[[ --height=100%%]] ..
[[ %s %s %s %s %s %s]],
[[ %s %s %s %s %s %s %s]],
opts.fzf_args or config.globals.fzf_args or '',
M.create_fzf_colors(opts.fzf_colors or config.globals.fzf_colors),
opts.fzf_layout or config.globals.fzf_layout,
@ -122,7 +122,8 @@ M.build_fzf_cli = function(opts, debug_print)
utils._if(actions.expect(opts.actions), actions.expect(opts.actions), ''),
utils._if(opts.nomulti, '--no-multi', '--multi'),
utils._if(opts.fzf_cli_args, opts.fzf_cli_args, ''),
utils._if(opts._fzf_cli_args, opts._fzf_cli_args, '')
utils._if(opts._fzf_cli_args, opts._fzf_cli_args, ''),
utils._if(opts._fzf_header_args, opts._fzf_header_args, '')
)
if debug_print then print(cli) end
return cli

@ -48,15 +48,32 @@ local get_grep_cmd = function(opts, search_query, no_esc)
return string.format('%s %s %s', command, search_query, search_path)
end
local function set_search_header(opts)
local function set_search_header(opts, type)
if not opts then opts = {} end
if opts.no_header then return opts end
if not opts.search or #opts.search==0 then return opts end
if not opts.cwd_header then opts.cwd_header = "cwd:" end
if not opts.search_header then opts.search_header = "Searching for:" end
opts._fzf_cli_args = opts._fzf_cli_args or ''
opts._fzf_cli_args = string.format([[%s --header=%s]],
opts._fzf_cli_args,
vim.fn.shellescape(("%s %s"):format(opts.search_header, opts.search)))
local header_str
local cwd_str = opts.cwd and ("%s %s"):format(opts.cwd_header, opts.cwd)
local search_str = opts.search and #opts.search > 0 and
("%s %s"):format(opts.search_header, opts.search)
-- 1: only search
-- 2: only cwd
-- otherwise, all
if type == 1 and search_str then header_str = search_str
elseif type == 2 and cwd_str then header_str = cwd_str
else
header_str = search_str or ''
if #header_str>0 and cwd_str and #cwd_str>0 then
header_str = header_str .. ", "
end
header_str = header_str .. (cwd_str or '')
end
if not header_str then return opts end
opts._fzf_header_args = opts._fzf_header_args or ''
opts._fzf_header_args = string.format([[%s --header=%s ]],
opts._fzf_header_args,
vim.fn.shellescape(header_str))
return opts
end
@ -132,6 +149,9 @@ M.live_grep = function(opts)
end
end
-- search query in header line
opts = set_search_header(opts, 2)
opts._cb_live_cmd = function(query)
if query and #query>0 and not opts.do_not_save_last_search then
last_search = {}
@ -174,6 +194,9 @@ M.live_grep_native = function(opts)
end
end
-- search query in header line
opts = set_search_header(opts, 2)
-- fzf already adds single quotes around the placeholder when expanding
-- for skim we surround it with double quotes or single quote searches fail
local placeholder = utils._if(opts._is_skim, '"{}"', '{q}')

Loading…
Cancel
Save