Closed tfriedel closed 4 weeks ago
I may have found a solution for this. I add this to my config:
-- Function to check if the environment is WSL
local function is_wsl()
local handle = io.popen("grep -i microsoft /proc/version")
local result = handle:read("*a")
handle:close()
return result ~= ""
end
-- Function to convert Windows path to WSL path and handle file opening
function OpenFile(path)
local final_path = path
if path:match("^%a:") then
local handle = io.popen('wslpath -u "' .. path .. '"')
final_path = handle:read("*a"):gsub("%s+", "")
handle:close()
end
-- Prevent the creation of the extra buffer
vim.cmd("bwipeout")
-- Open the converted path
vim.cmd("edit " .. final_path)
-- Reapply filetype detection and syntax highlighting
vim.cmd("doautocmd BufReadPost")
end
if is_wsl() then
-- Autocommand to override default behavior when opening files
vim.api.nvim_create_autocmd({ "BufReadCmd" }, {
pattern = "*",
callback = function()
OpenFile(vim.fn.expand("<afile>"))
end,
group = vim.api.nvim_create_augroup("OverrideEdit", { clear = true }),
})
endnd
actually, this seemed to work, but caused some issues. I'm afraid I'm out of ideas and think it must be fixed either in neovim or goneovim.
If I use the wsl version of goneovim and I drag a file from windows explorer onto it, opening the file will fail. This is because the file path looks like C:\Users...
To open it, it would need to be converted to something like /mnt/C/Users
In wsl there's a tool for converting paths: wslpath 'C:\Users\yourusername\Documents\file.txt'
It would be great if this would be called before opening such a file.