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

Can this plugin surpport for Windows platform? #82

Open
Zim-Inn opened this issue Oct 6, 2024 · 9 comments
Open

Can this plugin surpport for Windows platform? #82

Zim-Inn opened this issue Oct 6, 2024 · 9 comments
Labels
question Further information is requested

Comments

@Zim-Inn
Copy link

Zim-Inn commented Oct 6, 2024

image
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:
image

My home dir is zimiq.
image
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.

@alker0
Copy link
Owner

alker0 commented Oct 7, 2024

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.

@alker0 alker0 added the question Further information is requested label Oct 7, 2024
@Zim-Inn
Copy link
Author

Zim-Inn commented Oct 7, 2024

{ vim.fn.escape(home:gsub('\\', '/') .. '/.local/share/chezmoi/*', '.~$[ ') }

it works but ...
Snipaste_2024-10-07_23-36-55
image

let g:chezmoi#source_dir_path = fnamemodify(g:chezmoi#source_dir_path, ':p')

@Zim-Inn
Copy link
Author

Zim-Inn commented Oct 7, 2024

I don't know whether the new error affect most function of chezmoi.

@alker0
Copy link
Owner

alker0 commented Oct 8, 2024

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.

@alker0
Copy link
Owner

alker0 commented Oct 8, 2024

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,

@Zim-Inn
Copy link
Author

Zim-Inn commented Oct 8, 2024

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?

@Zim-Inn
Copy link
Author

Zim-Inn commented Oct 8, 2024

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?

@alker0
Copy link
Owner

alker0 commented Oct 9, 2024

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

@alker0
Copy link
Owner

alker0 commented Oct 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants