Is it possible to use a template in a run_once* file name? #3775
-
I don't know if I'm overcomplicating this, but I want to bootstrap my environment in either Windows or Linux. Another option I was considering is to use .chezmoiignore to have a .sh and a PowerShell template for each OS so that only the run_once* file that corresponds to the OS gets copied. But I'm not sure if .chezmoiignore works for run* files. What's the commonly used approach? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Did a quick search for I then tested it like this in PowerShell: > Set-Location "$(chezmoi source-path)"
### Create the two flavors of run_once_script that will alternate based on os
> mkdir .chezmoiscripts
> '"Hello World! PS1"' > .chezmoiscripts/run_once_script.ps1
> '#!/bin/bash'+"`n"+'echo "Hello World! sh"' > .chezmoiscripts/run_once_script.sh
### test it out - what's managed, what's ignored
> chezmoi ignored
> chezmoi managed
.chezmoiscripts/script.ps1
.chezmoiscripts/script.sh
### add template pattern to .chezmoiignore
> '.chezmoiscripts/script{{ if eq .chezmoi.os "windows" }}.sh{{ else }}.ps1{{ end }}' >> .chezmoiignore
### Test the tempalte syntax (on windows - the .sh should be ignored)
> Get-Content .chezmoiignore | chezmoi.exe execute-template
.chezmoiscripts/script.sh
### test again, this time with the .chezmoiignore entry in place
> chezmoi ignored
.chezmoiscripts/script.sh
> chezmoi managed
.chezmoiscripts/script.ps1 I'm guessing this is what you were asking for. Good Luck |
Beta Was this translation helpful? Give feedback.
-
No, it's not currently possible to templatize filenames. Use |
Beta Was this translation helpful? Give feedback.
Did a quick search for
chezmoiignore
andchezmoiscripts
and found #2510I then tested it like this in PowerShell: