Skip to content

How can I execute a template-based script before running chezmoi apply? #4221

Answered by bradenhilton
jbwfu asked this question in Q&A
Discussion options

You must be logged in to vote

Could you not replace your script with lookPaths in your external template? e.g.

{{- if lookPath "zsh" -}}
.config/shell/oh-my-zsh:
  type: git-repo
  url: https://github.com/ohmyzsh/ohmyzsh.git
  refreshPeriod: 168h
{{- end }}

For what it's worth, I prefer to build my configs with dicts/lists etc., then finally output them with to{Yaml,Toml,PrettyJson}. For example, here are my externals for mpv:

{{- $externals := dict -}}

{{- with $repo := "CogentRedTester/mpv-sub-select" -}}
{{-   $_ := set $externals "scripts/sub-select.lua" (dict
        "type" "file"
        "url" (printf "https://github.com/%s/raw/master/sub-select.lua" $repo)
        "refreshPeriod" "168h")
-}}
{{- end -}}

{{- …

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@jbwfu
Comment options

@bradenhilton
Comment options

@jbwfu
Comment options

@bradenhilton
Comment options

Answer selected by jbwfu
@jbwfu
Comment options

@halostatue
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants