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.

i
Template rendering only applies to non-encrypted config files. Encrypted files are restored as-is.

Marking Files as Templates

Terminal

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:

VariableDescription
{{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
~/.gitconfig (template)

[user]

name = {{vars.git_name}}

email = {{vars.git_email}}

Conditionals

Use {{#if ...}} blocks for platform-specific or context-specific sections.

~/.zshrc (template)

{{#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 ...}}:

Example

{{#unless platform == "win32"}}

alias ll="ls -la"

{{/unless}}

Tag Checks

Use the contains operator to check machine tags:

~/.zshrc (template)

{{#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 comparison
  • contains — check if a tag is present (used with tags)

Variable Resolution

The template context is built from machine variables and profile variables. When both define the same key, profile variables take priority.

~
Set machine-level defaults with machine var set, then override per-context with profile set-var.