twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.4k stars 493 forks source link

on windows cannot use .homeDir in .chezmoi.toml.tmpl #1877

Closed pwm1234-sri closed 2 years ago

pwm1234-sri commented 2 years ago

Describe the bug

When I use chezmoi init on windows with the variable .homeDir in a toml config file, .chezmoi.toml.tmpl, chezmoi generates an error with an error message about unescaped characters. This does not happen on linux.

The error also does not happen when using a yaml config file. (I did not try a json config file - I want to use either yaml or toml, so I can include comments, so json is not a good choice.) This is not a serious problem for me since yaml is just as good for me as toml, but I thought I should let you know.

Chezmoi seems like a great tool, and I am excited to be using it. Thanks!

To reproduce

Put .chezmoi.homeDir in the data section of a .chezmoi.toml.tmpl file and run chezmoi init on windows.

Expected behavior

The template expansion contains c:\Users\MyUserName.

Additional context

Add any other context about the problem here.

twpayne commented 2 years ago

The path separator in Windows is a backslash \, which is interpreted as an escape character in strings in most languages. You do not observe the problem on Linux because Linux uses a forward slash as the path separator.

chezmoi provides text templating, and it is your responsibility to ensure that the file generated by your template is correct. You might find the quote template function useful, for example:

{{ .chezmoi.homeDir | quote }}