diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 7e954b3..1874d86 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -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) diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index 53d9073..e9f91c7 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -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() diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index 8f7a7c9..d365771 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -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