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

fix: backward slash in url when using Windows #29

Merged
merged 1 commit into from
Mar 10, 2024
Merged

Conversation

AnsonH
Copy link
Contributor

@AnsonH AnsonH commented Feb 17, 2024

Bug

I'm using Neovim on Windows. I'm trying to run :OpenInGHFile inside a file that's inside a nested directory from the repo's root:

lvim/       (https://github.com/AnsonH/lvim)
├── lua/
│   └── user/
│       └── plugins.lua    <-- In this file
└── config.lua

However, the URL contains encoded backward slashes (%5C) and returns a "File not found" page:

https://github.com/AnsonH/lvim/blob/main/lua%5Cuser%5Cplugins.lua

Reason

It's caused by inconsistent file separator (/ vs \) in util.get_current_relative_file_path:

-- `nvim_buf_get_name` returns a path with backward slashes on Windows
-- e.g. C:\Users\Anson\AppData\Local\lvim\lua\user\plugins.lua
local absolute_file_path = vim.api.nvim_buf_get_name(0)

-- However this always return a path with forward slashes
-- e.g. C:/Users/Anson/AppData/Local/lvim
local git_path = vim.fn.system("git rev-parse --show-toplevel")

@Almo7aya Almo7aya self-requested a review March 10, 2024 19:48
@Almo7aya Almo7aya merged commit 613c189 into Almo7aya:main Mar 10, 2024
2 checks passed
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 this pull request may close these issues.

2 participants