Yazi not opening in cwd if space in path
Kayzels opened this issue · comments
In Windows, when I call yazi.nvim, it goes to a parent folder that is the part of the path before a space appears. I'm not sure if it's possibly that spaces aren't being checked for, or that it sees it as an additional argument?
If I have the path C:\Users\Name\Notes\Third Year\Course Name
, instead of opening in Course Name
, it opens in Notes
.
Calling Yazi directly in a terminal in Nvim opens in the correct location.
Hmm, I don't have access to a Windows machine but we can try to fix this together if you're up for a little experimentation.
I have some questions for you and then two ideas:
- do you use WSL or WSL2? or is there something newer? Idk about windows development these days lol 😄
- have you had issues with other neovim plugins? maybe there is something obvious that I have missed but others have solved.
- do you think your choice of terminal emulator / neovide / something else could affect this? what are you using?
- how do you start yazi.nvim? this probably doesn't matter but just want to make sure you don't have anything crazy going on
Ideas:
- I implemented two new things: debug logging that can help diagnose this, as well as a potential fix for it in #69 . Can you try that out? You can do it with lazy.nvim by setting the option
branch = "try-to-fix-windows-path-issue"
in your yazi.nvim plugin spec - It might solve it right away, but in case not, you can follow the instructions in the PR and enable logging.
:checkhealth yazi
will show you where the log file is, and you can paste its contents here
Here are more detailed instructions:
-
Save this file as
repro.lua
-- DO NOT change the paths and don't remove the colorscheme local root = vim.fn.fnamemodify('./.repro', ':p') -- set stdpaths to use .repro for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name end -- bootstrap lazy local lazypath = root .. '/plugins/lazy.nvim' if not vim.loop.fs_stat(lazypath) then vim.fn.system({ 'git', 'clone', '--filter=blob:none', 'https://github.com/folke/lazy.nvim.git', lazypath, }) end vim.opt.runtimepath:prepend(lazypath) vim.g.mapleader = ' ' -- install plugins local plugins = { 'folke/tokyonight.nvim', { 'mikavilpas/yazi.nvim', branch = 'try-to-fix-windows-path-issue', dependencies = { 'nvim-lua/plenary.nvim', }, event = 'VeryLazy', keys = { { -- 👇 choose your own keymapping '<leader>fy', function() require('yazi').yazi() end, { desc = 'Open the file manager' }, }, }, opts = { open_for_directories = false, log_level = vim.log.levels.DEBUG, }, }, } require('lazy').setup(plugins, { root = root .. '/plugins', }) vim.cmd.colorscheme('tokyonight') -- add anything else here
-
Run the following command to enter neovim running the
repro.lua
script:nvim -u repro.lua -c "lua require('lazy').update()"
-
You should now see neovim running. In this reproduction (repro) session,
yazi.nvim will now log messages to a log file. Execute the following command
in neovim:checkhealth yazi
You should see something like this:
yazi: require("yazi.health").check() yazi - yazi.nvim log file is at /Users/mikavilpas/git/yazi.nvim/.repro//state/nvim/yazi.log - hint: use gf to open the file path under the cursor - OK yazi
Open the log file (e.g. by placing the cursor on the path and pressing
gf
)
and send me the contents.
I'll test this now. I think it's possibly got to do with vim.fn.filenameescape
, as discussed in vim/vim#541.
Hmm, I don't have access to a Windows machine but we can try to fix this together if you're up for a little experimentation.
Ah, I can imagine this might make it trickier.
Do you use WSL or WSL2? or is there something newer? Idk about windows development these days lol 😄
I don't use either WSL or WSL2. Neovim actually works fine on native Windows now.
Have you had issues with other neovim plugins? maybe there is something obvious that I have missed but others have solved.
I think Neotree also had this issue before, discussed in nvim-neo-tree/neo-tree.nvim#1076 and they solved it in nvim-neo-tree/neo-tree.nvim#1077
Do you think your choice of terminal emulator / neovide / something else could affect this? what are you using?
I doubt it makes a difference. I use Powershell 7 inside Windows Terminal.
How do you start yazi.nvim? this probably doesn't matter but just want to make sure you don't have anything crazy going on
I've got it as an entry for Lazy.nvim. Originally, I called it without sending in vim.fn.getcwd()
, but I added that to see if it would make a difference.
{
"mikavilpas/yazi.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
},
event = "VeryLazy",
keys = {
{
"<leader>y",
function()
require("yazi").yazi(nil, vim.fn.getcwd())
end,
{ desc = "Explorer Yazi" },
},
},
}
I implemented two new things: debug logging that can help diagnose this, as well as a potential fix for it in Try to fix windows path issue #69 . Can you try that out? You can do it with lazy.nvim by setting the option
branch = "try-to-fix-windows-path-issue"
in your yazi.nvim plugin spec
I will send the results of this and the guide in your next post soon.
I created a folder for your repro code, and ran Neovim using it. Unfortunately, calling the health check lead to:
yazi: require("yazi.health").check()
yazi ~
- WARNING yazi --version looks unexpected, saw �7�[>q�_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA�\�[c�8Yazi 0.2.5 (386dd4c 2024-05-08)
- ERROR Failed to run healthcheck for "yazi" plugin. Exception:
...gram Files/Neovim/share/nvim/runtime/lua/vim/version.lua:174: attempt to index local 'version' (a nil value)
Possibly, the warning is due to having extra symbols in my prompt.
I'm going to test it with just changing the branch in my normal config, and see what the results of that are.
Ok, thanks for the detailed response! Finally a useful error message - hopefully this will lead to resolving the issue.
I myself use starship (https://starship.rs/) in my prompt and have these set:
$ echo $PROMPT
$(/opt/homebrew/bin/starship prompt --terminal-width="$COLUMNS" --keymap="${KEYMAP:-}" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="${STARSHIP_DURATION:-}" --jobs="$STARSHIP_JOBS_COUNT")
The path issue was reported to be solved on that branch by someone else using Windows in #71, although that was only with the reproduction environment for now.
I suspect your terminal settings might be off in a weird way. I googled a bit and found this, maybe you could try this out
Btw, do you get the extra symbols in your output if you run
:= vim.fn.system('yazi --version')
Btw, do you get the extra symbols in your output if you run
:= vim.fn.system('yazi --version')
I do, unfortunately. I've never been able to figure out why, or how to remove them. It happens with any command, whether it's called through Lua, or directly.
For example:
echo system("ls")
also prints those weird characters. I'm not sure if they're an escape sequence.
From what I can tell, its related to neovim/neovim#25800
EDIT:
I was able to fix some of the extra symbols by changing the shellcmdflag, but it doesn't work for Yazi.
vim.opt.shellcmdflag =
"-NoProfile -NoLogo -ExecutionPolicy RemoteSigned -NonInteractive -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();$PSDefaultParameterValues['Out-File:Encoding']='utf8';$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;"
:= vim.fn.system("yazi --version")
gives
^[7^[[>q^[_Gi=31,s=1,v=1,a=q,t=d,f=24;AAAA^[\^[[c^[8Yazi 0.2.5 (386dd4c 2024-05-08)
:= vim.fn.system("python --version")
gives
Python 3.10.7
Hmm, I read the discussion and it seems to me that this is some weird limitation in neovim itself.
Is it related to powershell? I have seen some neovim users on reddit report that wezterm has had really good windows support, it might be a good option to check out - although I don't know if that means a big change to your workflow.
If you happen to find a way this could be worked around, I would be willing to try it together. Let me know if you have any ideas.
Closing this for now, although if any ideas can be thought of, let's continue investigating.
I'm going to try some things today, but I was able to create a log file by removing the ^ at the start for the string match.
local semver = raw_version:match('[Yy]azi (%w+%.%w+%.%w+)')
For the log file, the output for the file with spaces is:
[2024-05-14 12:17:46] DEBUG Opening yazi with the command: (yazi "C:\Users\Kyzan\Documents\Unisa\Third\ Year\COS3701\ Theoretical\ Computer\ Science\ III\COS3701\ Notes" --local-events "rename,delete,trash,move" --chooser-file "C:\Users\Kyzan\AppData\Local\Temp\nvim.0\FgPbh7\0" > "C:\Users\Kyzan\AppData\Local\Temp\nvim.0\FgPbh7\1")
From that, because it's already in quotation marks, it seems to me that spaces shouldn't be escaped, and it should work. Will see if I can get that working.