Back to Chezmoi

Source state attributes

assets/chezmoi.io/docs/reference/source-state-attributes.md

2.70.25.2 KB
Original Source

Source state attributes

chezmoi stores the source state of files, symbolic links, and directories in regular files and directories in the source directory (~/.local/share/chezmoi by default). This location can be overridden with the -S flag or by giving a value for sourceDir in the configuration file. Directory targets are represented as directories in the source state. All other target types are represented as files in the source state. Some state is encoded in the source file names.

Attributes can be changed by renaming the file in the source state or with the chattr command.

The following prefixes and suffixes are special, and are collectively referred to as "attributes":

PrefixEffect
after_Run script after updating the destination
before_Run script before updating the destination
create_Ensure that the file exists, and create it with contents if it does not
dot_Rename to use a leading dot, e.g. dot_foo becomes .foo
empty_Ensure the file exists, even if is empty. By default, empty files are removed
encrypted_Encrypt the file in the source state
external_Ignore attributes in child entries
exact_Remove anything not managed by chezmoi
executable_Add executable permissions to the target file
literal_Stop parsing prefix attributes
modify_Treat the contents as a script that modifies an existing file
once_Only run the script if its contents have not been run successfully before
onchange_Only run the script if its contents have not been run successfully before with the same filename
private_Remove all group and world permissions from the target file or directory
readonly_Remove all write permissions from the target file or directory
remove_Remove the file or symlink if it exists or the directory if it is empty
run_Treat the contents as a script to run
symlink_Create a symlink instead of a regular file
SuffixEffect
.literalStop parsing suffix attributes
.tmplTreat the contents of the source file as a template

Different target types allow different prefixes and suffixes. The order of prefixes is important.

Target typeSource typeAllowed prefixes in orderAllowed suffixes
DirectoryDirectoryremove_, external_, exact_, private_, readonly_, dot_none
Regular fileFileencrypted_, private_, readonly_, empty_, executable_, dot_.tmpl
Create fileFilecreate_, encrypted_, private_, readonly_, empty_, executable_, dot_.tmpl
Modify fileFilemodify_, encrypted_, private_, readonly_, executable_, dot_.tmpl
Remove fileFileremove_, dot_none
ScriptFilerun_, once_ or onchange_, before_ or after_.tmpl
Symbolic linkFilesymlink_, dot_.tmpl

The literal_ prefix and .literal suffix can appear anywhere and stop attribute parsing. This permits filenames that would otherwise conflict with chezmoi's attributes to be represented.

In addition, if the source file is encrypted, the suffix .age (when age encryption is used) or .asc (when gpg encryption is used) is stripped. These suffixes can be overridden with the age.suffix and gpg.suffix configuration variables.

chezmoi ignores all files and directories in the source directory that begin with a . with the exception of files and directories that begin with .chezmoi.