better handling of 'cwd' in 'live_rg' (should solve issue #166)

main
bhagwan 3 years ago
parent 510aca8658
commit 67163f4c5f

@ -524,6 +524,10 @@ function M.normalize_opts(opts, defaults)
if opts.cwd and #opts.cwd > 0 then
opts.cwd = vim.fn.expand(opts.cwd)
if not vim.loop.fs_stat(opts.cwd) then
utils.warn(("Unable to access '%s', removing 'cwd' option."):format(opts.cwd))
opts.cwd = nil
end
end
local executable = function(binary, fncerr, strerr)

@ -41,7 +41,7 @@ M.fzf = function(opts, contents)
fzf_win:attach_previewer(previewer)
fzf_win:create()
local selected = fzf.raw_fzf(contents, M.build_fzf_cli(opts),
{ fzf_binary = opts.fzf_bin })
{ fzf_binary = opts.fzf_bin, fzf_cwd = opts.cwd })
fzf_win:check_exit_status()
if fzf_win:autoclose() == nil or fzf_win:autoclose() then
fzf_win:close()

@ -213,10 +213,7 @@ M.live_grep_native = function(opts)
-- we need to escape them in the initial query
opts.fzf_opts['--cmd-query'] = vim.fn.shellescape(utils.sk_escape(query))
opts._fzf_cli_args = string.format("-i -c %s",
vim.fn.shellescape(
("(cd %s && %s)"):format(
vim.fn.shellescape(opts.cwd or '.'),
reload_command)))
vim.fn.shellescape(reload_command))
else
opts.fzf_fn = {}
if opts.exec_empty_query or (opts.search and #opts.search > 0) then
@ -231,9 +228,7 @@ M.live_grep_native = function(opts)
opts.fzf_opts['--query'] = vim.fn.shellescape(query)
opts._fzf_cli_args = string.format('--bind=%s',
vim.fn.shellescape(("change:reload:%s"):format(
("(cd %s && %s || true)"):format(
vim.fn.shellescape(opts.cwd or '.'),
reload_command))))
("%s || true"):format(reload_command))))
end
-- we cannot parse any entries as they're not getting called

Loading…
Cancel
Save