Documentation
Templates
Customize config files per machine with variables and conditionals
Overview
Templates let you maintain a single config file that adapts to each machine. Variable substitution and conditionals are evaluated during pull, so each machine gets a tailored version of the file.
Marking Files as Templates
configsync add config ~/.gitconfig --template
The --template flag tells ConfigSync to process the file through the template engine during pull.
Variable Substitution
Use double curly braces to insert variables. These built-in variables are always available:
| Variable | Description |
|---|---|
| {{platform}} | Operating system: darwin, linux, or win32 |
| {{hostname}} | Machine hostname |
| {{arch}} | CPU architecture: arm64, x64, etc. |
| {{home}} | Home directory path |
| {{vars.key}} | Custom machine or profile variable |
[user]
name = {{vars.git_name}}
email = {{vars.git_email}}
Conditionals
Use {{#if ...}} blocks for platform-specific or context-specific sections.
{{#if platform == "darwin"}}
export HOMEBREW_PREFIX=/opt/homebrew
{{/if}}
{{#if platform == "linux"}}
export HOMEBREW_PREFIX=/home/linuxbrew/.linuxbrew
{{/if}}
The {{#unless ...}} block is the inverse of {{#if ...}}:
{{#unless platform == "win32"}}
alias ll="ls -la"
{{/unless}}
Tag Checks
Use the contains operator to check machine tags:
{{#if tags contains "work"}}
source ~/.work-aliases
export CORP_PROXY=http://proxy.corp:8080
{{/if}}
Operators
Template conditionals support the following operators:
==— equality comparison!=— inequality comparisoncontains— check if a tag is present (used withtags)
Variable Resolution
The template context is built from machine variables and profile variables. When both define the same key, profile variables take priority.
machine var set, then override per-context with profile set-var.