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

Escaping dots in setValueAtPath or deleteValueAtPath #2813

Closed
felipecrs opened this issue Mar 3, 2023 · 4 comments
Closed

Escaping dots in setValueAtPath or deleteValueAtPath #2813

felipecrs opened this issue Mar 3, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@felipecrs
Copy link
Contributor

Is your feature request related to a problem? Please describe.

I'm now trying to use modify templates to edit my VS Code config, and its keys are full of dots:

{
    "window.titleBarStyle": "custom",
    "window.zoomLevel": 1,
    "editor.fontFamily": "FiraCode Nerd Font Mono"
}

However, these two chezmoi template functions interpret dots as nesting for keys.

Describe the solution you'd like

If there was a way to escape them, it would be nice. Perhaps:

{{ setValueAtPath "window\.titleBarStyle" "custom" }}

Describe alternatives you've considered

Fortunately, for my case I only need to set top level keys, so I can still use Sprig's set.

Additional context

N/A

@felipecrs felipecrs added the enhancement New feature or request label Mar 3, 2023
@bradenhilton
Copy link
Collaborator

Maybe they should optionally accept a list of keys instead of splitting a path string?

@twpayne
Copy link
Owner

twpayne commented Mar 3, 2023

Maybe they should optionally accept a list of keys instead of splitting a path string?

Actually, they already do: https://www.chezmoi.io/reference/templates/functions/setValueAtPath/

setValueAtPath modifies dict to set the value at path to value and returns dict. path can be either a string containing a .-separated list of keys or a list of keys"

So @felipecrs you should already be able to do:

{{ setValueAtPath (list "window.titleBarStyle") "custom" }}

@felipecrs
Copy link
Contributor Author

Oh, that's great. Thank you.

@felipecrs felipecrs closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2023
@bradenhilton
Copy link
Collaborator

@twpayne Ahh, I was looking at the code and got confused after going back and forth from keysFromPath (string) and setValueAtPathTemplateFunc (any) a few times.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants