Skip to main content

Include

Exampleโ€‹

.aliae.yaml
aliae: !include "{{ .Home }}/.aliae/aliases.yaml"
env: !include_dir "{{ .Home }}/.aliae/envs"
$HOME/.aliae/aliases.yaml
- name: g
value: git
- name: k
value: kubectl

Descriptionโ€‹

The !include and !include_dir yaml tags allow you to include a single file or a directory of .yaml files respectively. This allows for clean organization of aliae, envs, and all other things handled by Aliae. File/Directory paths support templating.

If the directory given to !include_dir does not exist, it is treated as empty rather than raising an error. This lets you define a multi-folder config layout upfront and add the subfolders as you need them.

Inline Includeโ€‹

If you want to have a more fine grained control over the included file, you can use the !include tag inline in combination with other defined aliases.

.aliae.yaml
aliae:
- !include "{{ .Home }}/.aliae/kubernetes.yaml"
- name: g
value: git
$HOME/.aliae/kubernetes.yaml
- name: k
value: kubectl
- name: kg
value: kubectl get
- name: kgpo
value: kubectl get pod
- name: ksysgpo
value: kubectl --namespace=kube-system get pod
- name: krm
value: kubectl delete
- name: krmf
value: kubectl delete -f
- name: krming
value: kubectl delete ingress
- name: krmingl
value: kubectl delete ingress -l
- name: krmingall
value: kubectl delete ingress --all-namespaces
- name: kgsvcoyaml
value: kubectl get service -o=yaml
- name: kgsvcwn
value: kubectl get service --watch --namespace
- name: kgsvcslwn
value: kubectl get service --show-labels --watch --namespace
- name: kgwf
value: kubectl get --watch -f

Conditional Includeโ€‹

Both !include and !include_dir support an optional if=<condition> marker, using the same conditional statement syntax as the if field. When the condition evaluates to false, the include is skipped entirely and nothing is read from disk. The marker must live inside the same quotes as the path โ€” a bare, unquoted include can't carry one, since the underlying YAML document has to be valid before this preprocessing ever runs. Use single quotes to wrap the whole argument when the condition itself needs double quotes, so nothing needs escaping:

.aliae.yaml
env: !include '{{ .Home }}/.aliae/kubernetes-env.yaml if=hasCommand "kubectl"'
aliae:
- !include '{{ .Home }}/.aliae/kubernetes.yaml if=hasCommand "kubectl"'
- name: g
value: git

Section Filesโ€‹

A file included directly at a section's own key (alias: !include ..., not the inline list-item form above) may itself be wrapped in one or more of Aliae's top-level keys โ€” alias, env, path, cdpath, script, or link โ€” instead of a bare list. This lets you keep everything for one "workflow" together in a single file, and pull only the relevant section in at each include site. Only the section matching the include's own key is used; any other sections in the file are ignored at that site.

.aliae.yaml
alias: !include "{{ .Home }}/.aliae/python.yaml"
env: !include "{{ .Home }}/.aliae/python.yaml"
$HOME/.aliae/python.yaml
alias:
- name: venv
value: python -m venv .venv
env:
- name: PYTHONDONTWRITEBYTECODE
value: "1"

A file that doesn't carry the section being included resolves to nothing, same as a false conditional include. Section files can also be used with !include_dir: each file in the directory contributes only its own matching section, and a file that doesn't carry that section is skipped. This is not supported for the inline list-item form, since there's no single destination key for an entry inside an existing list.