Can this plugin surpport for Windows platform?
As you see, I found that env variable always be nil on windows ,so I change the line to make it has a right value.
local home = (os.getenv("HOME") ~= nil and {os.getenv("HOME")} or {os.getenv("Homepath")})[1]
But finally, it still process failed at the below line:
My home dir is zimiq.
So I think the Unknown operator may be related to /zimiq's /zi
I have no way to detect it futher. Hope you can give me some help.
Thank you for your explaining the situation in detail.
This issue likely stems from the pattern rule of autocmd that's applied in the following line of your init.lua:
pattern = { home .. '/.local/share/chezmoi/*' }
The pattern field is set up to include the value of home, which value should contain backslashes (\) as the path separator. However, in the pattern of autocmd, \ is a special character that affects path matching behavior. Therefore, you need to replace every \ with a forward slash (/) to use it as a simple path separator.
Please try modifying your init.lua as follows and let me know if it works.
pattern = { home:gsub('\\', '/') .. '/.local/share/chezmoi/*' }
-- for more strictly:
pattern = { vim.fn.escape(home:gsub('\\', '/') .. '/.local/share/chezmoi/*', '.~$[ ') }
I hope this helps you. Plus, thank you for informing me about the HOMEPATH environment variable, which can be used to get the home directory path in Windows.
{ vim.fn.escape(home:gsub('\\', '/') .. '/.local/share/chezmoi/*', '.~$[ ') }
it works but ...
let g:chezmoi#source_dir_path = fnamemodify(g:chezmoi#source_dir_path, ':p')
I don't know whether the new error affect most function of chezmoi.
Hmm... Would removing the brackets ({}) from around the pattern work?
-- pattern = { vim.fn.escape(home:gsub('\\', '/') .. '/.local/share/chezmoi/*', '.~$[ ') },
pattern = vim.fn.escape(home:gsub('\\', '/') .. '/.local/share/chezmoi/*', '.~$[ '),
Surrounding a value with brackets creates a list in Lua, ~~but not valid as pattern value, which should be of string type~~.
Oh, create_autocmd() accepts even a list as its pattern value. I didn't know that. It wouldn't need fix.
The chezmoi#source_dir_path option seems to be set to a list somewhere, as indicated by the error message. However, I haven't been able to reproduce this issue in my Windows environment yet. What output would you get if you modified your init function as follows?
init = function()
vim.g["chezmoi#use_tmp_dir"] = 1
vim.g["chezmoi#source_dir_path"] = home .. '/.local/share/chezmoi'
print(vim.g["chezmoi#source_dir_path"])
end,
Surrounding a value with brackets creates a list in
ok, I got it. I have fixed it in my local. Could I give a PR to your repo?
Excuse me but ...
I am wondering that the chezmoi.lua is at ~\AppData\Local\nvim-data\lazy\LazyVim\lua\lazyvim\plugins\extras\util\chezmoi.lua so that I think the file is in this repo. But in fact there is no file named chezmoi.lua.
I should push commit to which repo?
You shouldn't need to submit a PR. Thank you.
You should not need to modify chezmoi.lua, so revert it to its original state. Instead, set the HOME environment variable to a fixed value before LazyVim runs lazy.nvim. For example, you can add the following lines to ~/AppData/Local/nvim/lua/config/options.lua:
if os.getenv("HOME") == nil then
-- with Vim API
vim.fn.setenv("HOME", vim.fn.expand("~"))
-- or Neovim API
vim.fn.setenv("HOME", vim.env.HOMEDRIVE .. vim.env.HOMEPATH)
-- or pure Lua
vim.fn.setenv("HOME", os.getenv("HOMEDRIVE") .. os.getenv("HOMEPATH"))
end
You may need to replace backslashes (\) with forward slashes (/) in the HOME environment variable if you are still encountering an error. Backslashes (\) in file paths can sometimes cause issues. This plugin automatically replaces backslashes for file path processing, but other plugins might not do so.
if os.getenv("HOME") == nil then
-- with Vim API
local home = vim.fn.expand("~")
-- or Neovim API
local home = vim.env.HOMEDRIVE .. vim.env.HOMEPATH
-- or pure Lua
local home = os.getenv("HOMEDRIVE") .. os.getenv("HOMEPATH")
vim.fn.setenv("HOME", home:gsub("\\", "/"))
end