chezmoi.vim icon indicating copy to clipboard operation
chezmoi.vim copied to clipboard

Can this plugin surpport for Windows platform?

Open Zim-Inn opened this issue 1 year ago • 9 comments

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.

Zim-Inn avatar Oct 06 '24 16:10 Zim-Inn

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 avatar Oct 07 '24 05:10 alker0

{ 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 avatar Oct 07 '24 15:10 Zim-Inn

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

Zim-Inn avatar Oct 07 '24 15:10 Zim-Inn

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 avatar Oct 08 '24 00:10 alker0

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,

alker0 avatar Oct 08 '24 10:10 alker0

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 avatar Oct 08 '24 15:10 Zim-Inn

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?

Zim-Inn avatar Oct 08 '24 16:10 Zim-Inn

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 avatar Oct 09 '24 00:10 alker0

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

alker0 avatar Oct 10 '24 22:10 alker0