akinsho / akinsho/toggleterm.nvim
[BUG] set `dir = git_dir` will not make toggleterm try and derive the git repo directory
- Dominant language
- Lua
- Stars
- 5.6k
- Forks
- 206
- PR merge metrics
- No merged PRs in 30d
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Current Behavior
according to the documentation i setting the `dir` option to `git_dir` in neovim commandline like` ToggleTerm dir=git_dir`, but the directory in toggleterm does not change as expected
### Expected Behavior
this seems to be caused by vim.fn.isdirectory not recognizing git_dir. i find the function that toggleterm.nvim used to get or create terminal
``` lua
function M.get_or_create_term(num, dir, direction, name)
local term = M.get(num)
if term then return term, false end
if dir and fn.isdirectory(fn.expand(dir)) == 0 then dir = nil end
return Terminal:new({ id = num, dir = dir, direction = direction, display_name = name }), true
end
```
and find it depend `vim.fn.isdirectory()` to recognize directory, but `git_dir` will be not recognized.
Edited:
I added an additional if condition in my local `toggleterm.nvim`, which made `ToggleTerm dir=git_dir` work properly. I'm not sure if this will affect other behaviors.
``` lua
function M.get_or_create_term(num, dir, direction, name)
local term = M.get(num)
if term then return term, false end
-- HACK: `dir ~= "git_dir"` is a hack to make git_dir work
if dir and fn.isdirectory(fn.expand(dir)) == 0 and dir ~= "git_dir" then dir = nil end
return Terminal:new({ id = num, dir = dir, direction = direction, display_name = name }), true
end
```
### Steps To Reproduce
i set toggleterm.nvim in my configuration like this
``` lua
{
"akinsho/toggleterm.nvim",
version = "*",
event = "VeryLazy",
cmd = { "ToggleTerm", "TermExec" },
...
opts = {
on_create = function(term)
print(term.dir)
end,
autochdir = false,
direction = "horizontal",
shell = vim.fn.has("win32") == 1 and "pwsh" or vim.o.shell,
float_opts = {
border = "rounded",
},
},
}
```
### Environment
```Markdown
- OS: Windows 11 23H2
- neovim version: NVIM v0.10.0
- Shell: PowerShell 7.4.2
```
### Anything else?
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.