bugfix: cwd when using relative path sub-directories (closes #375)

main
bhagwan 2 years ago
parent 6fd4459d0c
commit 92f063632e

@ -742,6 +742,13 @@ function M.normalize_opts(opts, defaults)
if not vim.loop.fs_stat(opts.cwd) then
utils.warn(("Unable to access '%s', removing 'cwd' option."):format(opts.cwd))
opts.cwd = nil
else
-- relative paths in cwd are inaccessible when using multiprocess
-- as the external process have no awareness of our current working
-- directory so we must convert to full path (#375)
if not path.starts_with_separator(opts.cwd) then
opts.cwd = path.join({ vim.loop.cwd(), opts.cwd })
end
end
end

@ -459,14 +459,22 @@ M.set_header = function(opts, flags)
if not opts.cwd_header then opts.cwd_header = "cwd:" end
if not opts.grep_header then opts.grep_header = "Grep string:" end
if not opts.cwd and opts.show_cwd_header then opts.cwd = vim.loop.cwd() end
local header_str
local cwd_str =
opts.cwd and (opts.show_cwd_header ~= false) and
(opts.show_cwd_header or opts.cwd ~= vim.loop.cwd()) and
("%s %s"):format(opts.cwd_header,
utils.ansi_codes.red(opts.cwd:gsub("^"..vim.env.HOME, "~")))
local search_str = opts.search and #opts.search > 0 and
local cwd_str, header_str
local search_str = flags ~= 2 and opts.search and #opts.search>0 and
("%s %s"):format(opts.grep_header, utils.ansi_codes.red(opts.search))
if flags ~= 1 and opts.cwd and
(opts.show_cwd_header ~= false) and
(opts.show_cwd_header or opts.cwd ~= vim.loop.cwd()) then
local cwd = opts.cwd
if path.starts_with_separator(cwd) and cwd ~= vim.loop.cwd() then
-- since we're always converting cwd to full path
-- try to convert it back to relative for display
cwd = path.relative(cwd, vim.loop.cwd())
end
-- make our home dir path look pretty
cwd = cwd:gsub("^"..vim.env.HOME, "~")
cwd_str = ("%s %s"):format(opts.cwd_header, utils.ansi_codes.red(cwd))
end
-- 1: only search
-- 2: only cwd
-- otherwise, all

Loading…
Cancel
Save