Skip to main content

Templates

Exampleโ€‹

env:
- name: POSH_THEME
value: '{{ .Home }}/.configs/posh.omp.yaml'

Descriptionโ€‹

Some fields have text/template abilities, allowing to reuse the same configuration across multiple environments resulting in environment specific values.

Out of the box you get the following functionality:

Variablesโ€‹

NameTypeDescriptionExample
.Shellstringthe current shell name{{ .Shell }}
.ShellLikeboolwhether shell is bash/zsh/fish/tcsh/pwsh/powershell{{ .ShellLike }}
.Hostnamestringthe system hostname{{ .Hostname }}
.WSLboolwhether runtime is in WSL{{ .WSL }}
.Homestringthe user's $HOME folder{{ .Home }}/go/bin/aliae
.OSstringthe current operating system{{ .Home }}/go/bin/aliae{{ if eq .OS "windows" }}.exe{{ end }}
.Archstringthe aliae executable architecture{{ .Home }}/go/bin/aliae-{{ .Arch }}{{ if eq .OS "windows" }}.exe{{ end }}
.ConfigPathstringthe resolved aliae config file path{{ .ConfigPath }}
.ConfigDirstringthe directory of the resolved config{{ .ConfigDir }}/partials/env.yaml
.Envmapprocess environment variables map{{ .Env.DOTFILES }}
.Varmapprecomputed variables from top-level var entries{{ .Var.WORKSPACE }}

Functionsโ€‹

NameTypeDescriptionExample
envstringretrieve an environment variable value{{ env "POSH_THEME" }}
matchbooleanmatch a shell name to one or multiple options{{ match .Shell "zsh" "bash" }}
hasCommandbooleancheck if an executable exists (cached per command){{ hasCommand "oh-my-posh" }}
hasCommandNoCachebooleancheck if an executable exists without using cache{{ hasCommandNoCache "oh-my-posh" }}
fileExistsbooleancheck if a file exists relative to .Home by default{{ fileExists ".cache/aliae" }}
dirExistsbooleancheck if a directory exists relative to .Home by default{{ dirExists ".cache" }}
setArgstringemit shell-specific argument assignment statement{{ setArg "TARGET_HOST" 1 }}
progressstringemit shell OSC progress command (0-100 or "reset"){{ progress 71 }}

fileExists and dirExists resolve paths relative to .Home unless the path is absolute. Results are cached per resolved path during the current run. If the same path is checked again later (for example from script), the cached result is reused instead of checking the filesystem again.

hasCommand caches results per command during the current run. Use hasCommandNoCache when you need a fresh check after mutating PATH in the same run.

var entries are computed before other config sections render. You can use .Var.<Name> in other template values and if expressions. To prevent loops, var entries cannot reference .Var in their own value or if.

.ShellLike is true for bash, zsh, fish, tcsh, pwsh, and powershell.

setArg converts one-based argument indexes into shell syntax:

  • Bash/Zsh: TARGET_HOST=$1
  • Fish: set TARGET_HOST $argv[1]
  • Pwsh/PowerShell: $TARGET_HOST = $args[0]
  • Tcsh: set TARGET_HOST=$1

progress renders shell-specific commands:

  • Bash/Zsh/Fish/Tcsh: printf '\033]9;4;1;71\007'
  • PowerShell/Pwsh: [Console]::Out.Write("$([char]27)]9;4;1;71$([char]7)")
  • Reset: {{ progress "reset" }}
tip

When using a template in a single line, you have to use quotes to wrap the template string.

env:
- name: POSH_THEME
value: '{{ .Home }}/.configs/posh.omp.yaml'

Precomputed var exampleโ€‹

var:
- name: WORKSPACE
value: '{{ .Home }}/src'
- name: ENABLE_TOOLS
value: enabled

env:
- name: WORKSPACE
value: '{{ .Var.WORKSPACE }}'

alias:
- name: cws
value: cd '{{ .Var.WORKSPACE }}'
if: eq .Var.ENABLE_TOOLS "enabled"