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

Opening neovim in / directory causes the status line to error. #250

Closed
David-Aguilo opened this issue Mar 18, 2024 · 5 comments · Fixed by #251
Closed

Opening neovim in / directory causes the status line to error. #250

David-Aguilo opened this issue Mar 18, 2024 · 5 comments · Fixed by #251

Comments

@David-Aguilo
Copy link
Contributor

Describe the issue
Due to the way the cwd module of the statusline is generated. It produces an error when neovim is opened in the / directory.

M.cwd = function()
  local icon = "%#St_cwd_icon#" .. "󰉋 "
  local name = "%#St_cwd_text#" .. " " .. vim.loop.cwd():match "([^/\\]+)[/\\]*$" .. " "
  return (vim.o.columns > 85 and ("%#St_cwd_sep#" .. sep_l .. icon .. name)) or ""
end

I'm guessing the match statement cannot handle the directory just being / and it errors out.

I have already looked to see if the issue has been reported and it was for v2.0: #197

I have updated all my plugins to see if maybe I had an older version, but it still happens.

To reproduce

cd /
nvim

Expected Behaviour
No error.

Screenshots
imatge

Desktop

  • Operating System: ArchLinux
  • Terminal: alacritty
  • Version of Neovim: v0.9.5
@David-Aguilo
Copy link
Contributor Author

The issue can be fixed by replacing

vim.loop.cwd():match "([^/\\]+)[/\\]*$" .. " "

with

vim.fn.fnamemodify(vim.fn.getcwd(), ":t") .. " "

Though, then the working directory in the statusline appears blank.
imatge

@lucario387
Copy link
Collaborator

PR Welcome

@David-Aguilo
Copy link
Contributor Author

True, I don't know if this is the fix that is to be employed because it leaves the field blank, but sure, I'll make a PR. I'll try to see if I can get a better regex going which can handle both cases as well.

@lucario387
Copy link
Collaborator

When in doubt, if statements :)

@David-Aguilo
Copy link
Contributor Author

Done

siduck added a commit that referenced this issue Mar 18, 2024
* Changed cwd match statement so when nvim is opened in / it is shown correctly
 
---------

Co-authored-by: Sidhanth Rathod <siduck@tutanota.com>
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

Successfully merging a pull request may close this issue.

2 participants