Skip to content

Commit dca1c80

Browse files
authored
fix: autochdir for custom terminals (#553)
* fix: autochdir for custom terminals * refactor: use ternary expression can do it like this when the variable is now assigned outside of this block
1 parent fef08f3 commit dca1c80

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lua/toggleterm/terminal.lua

+3-5
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ end
485485
---@param size number?
486486
---@param direction string?
487487
function Terminal:open(size, direction)
488-
self.dir = _get_dir(self.dir)
488+
local cwd = fn.getcwd()
489+
self.dir = _get_dir(config.autochdir and cwd or self.dir)
489490
ui.set_origin_window()
490491
if direction then self:change_direction(direction) end
491492
if not self.bufnr or not api.nvim_buf_is_valid(self.bufnr) then
@@ -496,10 +497,7 @@ function Terminal:open(size, direction)
496497
local ok, err = pcall(opener, size, self)
497498
if not ok and err then return utils.notify(err, "error") end
498499
ui.switch_buf(self.bufnr)
499-
if config.autochdir then
500-
local cwd = fn.getcwd()
501-
if self.dir ~= cwd then self:change_dir(cwd) end
502-
end
500+
if config.autochdir and self.dir ~= cwd then self:change_dir(cwd) end
503501
end
504502
ui.hl_term(self)
505503
-- NOTE: it is important that this function is called at this point. i.e. the buffer has been correctly assigned

0 commit comments

Comments
 (0)