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

.chezmoi.cacheDir variable has mixed path separators on Windows #3473

Closed
drwicid opened this issue Jan 12, 2024 · 4 comments · Fixed by #3475
Closed

.chezmoi.cacheDir variable has mixed path separators on Windows #3473

drwicid opened this issue Jan 12, 2024 · 4 comments · Fixed by #3475
Labels
bug Something isn't working windows only This only affects Windows

Comments

@drwicid
Copy link

drwicid commented Jan 12, 2024

Describe the bug

On Windows, the .chezmoi.cacheDir variable uses mixed path separators. This may cause toml: non-hex character error if chezmoi reads the path string.

To reproduce

Quick repro of the mixed case:

> chezmoi execute-template "{{ .chezmoi.cacheDir }}"
C:\Users\drwic\.cache/chezmoi

To reproduce the error, create this config template:

encryption = "age"
[age]
   identity = "{{ .chezmoi.cacheDir }}/age.txt"

Execute chezmoi init

chezmoi: C:/Users/drwic/.local/share/chezmoi/home/.chezmoi.toml.tmpl: toml: non-hex character

Expected behavior

cacheDir should have consistent path separators.

Additional Info

Passing this config through execute-template:

encryption = "age"

[age]
   # Bug
   identity = "{{ .chezmoi.cacheDir }}/age.txt"

   # Workaround
   identity = "{{ .chezmoi.cacheDir | replaceAllRegex "\\\\" "/" }}/age.txt"

outputs:

encryption = "age"

[age]
   # Bug
   identity = "C:\Users\drwic\.cache/chezmoi/age.txt"

   # Workaround
   identity = "C:/Users/drwic/.cache/chezmoi/age.txt"
@twpayne twpayne added bug Something isn't working windows only This only affects Windows labels Jan 12, 2024
@twpayne
Copy link
Owner

twpayne commented Jan 12, 2024

Thanks for reporting this. It is fixed with #3475.

Note that a better work-around is to use the quote template function as this handles all characters that need to be escaped, not just backslashes.

[age]
    identity = {{ joinPath .chezmoi.cacheDir "age.txt" | quote }}

@halostatue
Copy link
Collaborator

You could also use | toToml instead of | quote.

@twpayne
Copy link
Owner

twpayne commented Jan 12, 2024

You could also use | toToml instead of | quote.

That's an even better solution, thank you.

@drwicid
Copy link
Author

drwicid commented Jan 12, 2024

Thanks for the alternatives. I'm two weeks into my chezmoi noob journey and loving this tool. I'll take this as an assignment to RTFM and master all those functions ;-)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working windows only This only affects Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants