Template Functions
All standardtext/template and text template functions from Sprig are included. chezmoi provides many additional functions.
General Functions
abortEmpty
Returns empty, causing the target file to be removed. Useful for conditionally creating files.
comment prefix string
Adds prefix to the beginning of each line in string.
completion shell
Returns shell completion script for the specified shell (bash, fish, powershell, zsh).
decrypt ciphertext
Decrypts ciphertext using the configured encryption method.
encrypt plaintext
Encrypts plaintext using the configured encryption method.
ensureLinePrefix prefix [addPrefix] string
Ensures each line in string has prefix. If addPrefix is specified, it’s added to lines missing prefix.
eqFold first second [more…]
Case-insensitive equality comparison.
exec command [args…]
Executes command with args and returns true if successful, false otherwise.
File Functions
include filename
Returns the literal contents of filename. Relative paths are interpreted relative to the source directory.
includeTemplate filename [data]
Executes the template in filename with optional data and returns the result.
stat name
Returns file information for name (name, size, mode, perm, modTime, isDir, type). Returns false if file doesn’t exist.
lstat name
Like stat, but doesn’t follow symbolic links.
glob pattern
Returns list of files matching pattern in the destination directory.
Execution Functions
output command [args…]
Returns the output of executing command with args. Exits with error if command fails.
outputList command argsList
Like output, but takes arguments as a list.
lookPath file
Returns the full path to file if found in PATH, empty string otherwise.
findExecutable file pathList
Finds file in pathList and returns the full path.
findOneExecutable fileList pathList
Finds the first executable from fileList in pathList.
isExecutable file
Returns true if file has executable permissions.
Path Functions
joinPath elements…
Joins path elements using the OS-specific path separator.
Data Conversion Functions
fromJson string
Parses string as JSON and returns the result.
fromJsonc string
Parses string as JSONC (JSON with comments).
fromToml string
Parses string as TOML.
fromYaml string
Parses string as YAML.
fromIni string
Parses string as INI format.
toJson data
Converts data to JSON format.
toPrettyJson [indent] data
Converts data to pretty-printed JSON.
toToml data
Converts data to TOML format.
toYaml data
Converts data to YAML format.
toIni data
Converts data to INI format.
String Functions
hexDecode string
Decodes hexadecimal string to bytes.
hexEncode string
Encodes string to hexadecimal.
quote values…
Double-quotes each value and joins with spaces.
squote values…
Single-quotes each value and joins with spaces.
quoteList list
Double-quotes each element in list.
replaceAllRegex pattern replacement string
Replaces all matches of regex pattern with replacement in string.
splitList separator string
Splits string by separator and returns a list.
toString value
Converts value to a string.
toStrings values…
Converts multiple values to strings.
Data Manipulation Functions
deleteValueAtPath path dict
Deletes the value at path in dict.
setValueAtPath path value dict
Sets value at path in dict.
pruneEmptyDicts dict
Removes all empty dictionaries from dict.
jq query input
Executes jq query on input and returns results.
Special Functions
mozillaInstallHash path
Returns Mozilla installation hash for path.
ioreg
Returns macOS IORegistry information (macOS only).
warnf format args…
Prints a warning message. Returns empty string.
getRedirectedURL url
Follows redirects and returns the final URL.
GitHub Functions
These functions integrate with GitHub’s API:gitHubKeysuser - Returns user’s public SSH keysgitHubLatestReleaserepo - Returns latest release infogitHubLatestReleaseAssetURLrepo pattern - Returns asset download URLgitHubLatestTagrepo - Returns latest tag namegitHubReleaserepo tag - Returns release info for taggitHubReleaseAssetURLrepo tag pattern - Returns asset URL for releasegitHubReleasesrepo - Returns all releasesgitHubTagsrepo - Returns all tags
Example
Password Manager Functions
See Password Manager Functions for:- 1Password (
onepassword,onepasswordDocument, etc.) - Bitwarden (
bitwarden,bitwardenFields, etc.) - LastPass (
lastpass,lastpassRaw) - Pass (
pass,passFields,passRaw) - Keeper (
keeper,keeperDataFields) - KeePassXC (
keepassxc,keepassxcAttribute) - And many more
Related Pages
- Template Variables - Built-in template variables
- Template Directives - File-specific template options
- Password Manager Functions - Secret management functions
- Sprig Functions - Additional functions from Sprig