akinsho / akinsho/toggleterm.nvim

[BUG] set `dir = git_dir` will not make toggleterm try and derive the git repo directory

Đang mở
#581 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Lua
Star
5.6k
Fork
206
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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_

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.