Skip to content

Using template variables in .chezmoiroot #1720

Description

@bdavs3

What exactly are you trying to do?

Hi! Let me first say that I really love this project.

Right now, I'm using a script that populates ~/.config/chezmoi/chezmoi.toml with a template variable, in hopes of changing .chezmoiroot according to a user's preferences. I'm curious as to whether this is currently possible.

What have you tried so far?

  • My current solution is to directly write to .chezmoiroot via my script, but I feel that a cleaner solution would be to keep the desired root with my template variables.
  • I've also (somewhat desperately) tried using .chezmoiroot.tmpl, as well as placing .chezmoiroot within the .chezmoitemplates directory.

Where else have you checked for solutions?

Output of any commands you've tried

Here is my .chezmoiroot:

{{ .team }}

And my ~/.config/chezmoi/chezmoi.toml:

[data]
    shell = 'bash'
    team = 'my-team'

In ~/.local/share/chezmoi I have the following:

my-team
│   dot_bashrc
│   dot_zshrc    
│   .chezmoiignore
.chezmoiroot
.git/
.gitignore
install.sh
README.md

Unfortunately when I run chezmoi diff, I get

my-team/.bashrc
my-team/.zshrc
install.sh
README.md

If I change .chezmoiroot to simply say my-team, I can confirm that things work properly when I run chezmoi diff:

.bashrc
.zshrc

Let me know if anyone has input!

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportSupport request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions