Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
mianm12 opened this issue May 20, 2024 · 0 comments
Open
1 task done

Comments

@mianm12
Copy link

mianm12 commented May 20, 2024

Is there an existing issue for this?

  • 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

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.

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

{
    "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

- OS: Windows 11 23H2
- neovim version: NVIM v0.10.0
- Shell: PowerShell 7.4.2

Anything else?

No response

@mianm12 mianm12 changed the title [BUG] set will dir = git_dir not make toggleterm try and derive the git repo directory [BUG] set dir = git_dir will not make toggleterm try and derive the git repo directory May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant