fix(terminal): spawn in effective CWD #41211

Problem:
`:terminal` does not respect the invocation-time CWD.
This wasn't noticeable with `:lcd` because the window-local CWD gets
applied to the new terminal buffer. But it is noticeable with `:bcd`.

Solution:
Specify `cwd` in the job spec.
This commit is contained in:
Justin M. Keyes
2026-08-07 07:44:19 -04:00
committed by GitHub
parent bc9d27b0bc
commit 2e0a5a596a
2 changed files with 19 additions and 7 deletions

View File

@@ -248,17 +248,20 @@ function M.ex_terminal(eap, shell_argv)
or smods.horizontal
or smods.vertical
-- Use the invocation-time CWD, before creating a new buffer.
local opts = { term = true, cwd = vim.fn.getcwd() }
if has_mods then
vim.cmd.new { mods = smods }
else
vim.cmd.enew { bang = eap.bang }
end
if shell_argv then -- No `cmd`, run 'shell'.
vim.fn.jobstart(shell_argv, { term = true })
else -- Run [cmd] in 'shell'.
vim.fn.jobstart(eap.args, { term = true })
end
vim.fn.jobstart(
shell_argv and shell_argv -- No `cmd`, run 'shell'.
or eap.args, -- Run [cmd] in 'shell'.
opts
)
end
function M.ex_uptime()