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โ
| Name | Type | Description | Example |
|---|---|---|---|
.Shell | string | the current shell name | {{ .Shell }} |
.ShellLike | bool | whether shell is bash/zsh/fish/tcsh/pwsh/powershell | {{ .ShellLike }} |
.Hostname | string | the system hostname | {{ .Hostname }} |
.WSL | bool | whether runtime is in WSL | {{ .WSL }} |
.Home | string | the user's $HOME folder | {{ .Home }}/go/bin/aliae |
.OS | string | the current operating system | {{ .Home }}/go/bin/aliae{{ if eq .OS "windows" }}.exe{{ end }} |
.Arch | string | the aliae executable architecture | {{ .Home }}/go/bin/aliae-{{ .Arch }}{{ if eq .OS "windows" }}.exe{{ end }} |
.ConfigPath | string | the resolved aliae config file path | {{ .ConfigPath }} |
.ConfigDir | string | the directory of the resolved config | {{ .ConfigDir }}/partials/env.yaml |
.Env | map | process environment variables map | {{ .Env.DOTFILES }} |
.Var | map | precomputed variables from top-level var entries | {{ .Var.WORKSPACE }} |
Functionsโ
| Name | Type | Description | Example |
|---|---|---|---|
env | string | retrieve an environment variable value | {{ env "POSH_THEME" }} |
match | boolean | match a shell name to one or multiple options | {{ match .Shell "zsh" "bash" }} |
hasCommand | boolean | check if an executable exists (cached per command) | {{ hasCommand "oh-my-posh" }} |
hasCommandNoCache | boolean | check if an executable exists without using cache | {{ hasCommandNoCache "oh-my-posh" }} |
fileExists | boolean | check if a file exists relative to .Home by default | {{ fileExists ".cache/aliae" }} |
dirExists | boolean | check if a directory exists relative to .Home by default | {{ dirExists ".cache" }} |
setArg | string | emit shell-specific argument assignment statement | {{ setArg "TARGET_HOST" 1 }} |
progress | string | emit 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" }}
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"