fix issue #28, added search header for cword/visual grep

main
bhagwan 3 years ago
parent 2c9438855c
commit cf583fe211

@ -51,7 +51,7 @@ M.build_fzf_cli = function(opts)
[[ %s --layout=%s --bind=%s --prompt=%s]] ..
[[ --preview-window='%s%s' --preview=%s]] ..
[[ --height=100%% --ansi]] ..
[[ %s %s %s %s]],
[[ %s %s %s %s %s]],
opts.fzf_args or config.globals.fzf_args or '',
opts.fzf_layout or config.globals.fzf_layout,
utils._if(opts.fzf_binds, opts.fzf_binds,
@ -64,6 +64,7 @@ M.build_fzf_cli = function(opts)
utils._if(opts.fzf_bin and opts.fzf_bin:find('sk')~=nil, "--inline-info", "--info=inline"),
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.cli_args, opts.cli_args, '')
)
-- print(cli)

@ -5,6 +5,7 @@ end
local fzf = require "fzf"
local config = require "fzf-lua.config"
local M = {}
function M.setup(opts)
@ -13,6 +14,9 @@ function M.setup(opts)
for k, _ in pairs(globals.winopts) do
if opts[k] ~= nil then globals.winopts[k] = opts[k] end
end
-- empty BAT_CONFIG_PATH so we don't conflict
-- with '$XDG_DATA_HOME/bat/config'
vim.env.BAT_CONFIG_PATH = ''
-- override the bat preview theme if set by caller
if globals.bat_theme and #globals.bat_theme > 0 then
vim.env.BAT_THEME = globals.bat_theme

@ -168,6 +168,16 @@ M.live_grep = function(opts)
opts.search = nil
end
local function set_search_header(opts)
if not opts then opts = {} end
if opts.no_header then return opts end
if not opts.search_header then opts.search_header = "Seaching for:" end
opts.fzf_cli_args = opts.fzf_cli_args or ''
opts.fzf_cli_args = string.format([[%s --header="%s '%s'"]],
opts.fzf_cli_args, opts.search_header, opts.search)
return opts
end
M.grep_last = function(opts)
if not opts then opts = {} end
opts.continue_last_search = true
@ -177,18 +187,21 @@ end
M.grep_cword = function(opts)
if not opts then opts = {} end
opts.search = vim.fn.expand("<cword>")
opts = set_search_header(opts)
return M.grep(opts)
end
M.grep_cWORD = function(opts)
if not opts then opts = {} end
opts.search = vim.fn.expand("<cWORD>")
opts = set_search_header(opts)
return M.grep(opts)
end
M.grep_visual = function(opts)
if not opts then opts = {} end
opts.search = utils.get_visual_selection()
opts = set_search_header(opts)
return M.grep(opts)
end

Loading…
Cancel
Save