Skip to content

Commit

Permalink
Add how to handle externally modified config files (#487)
Browse files Browse the repository at this point in the history
Add how to handle externally modified config files
  • Loading branch information
twpayne committed Nov 22, 2019
2 parents 7acba23 + 387cffa commit 1b655f9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/HOWTO.md
Expand Up @@ -7,6 +7,7 @@
* [Create a config file on a new machine automatically](#create-a-config-file-on-a-new-machine-automatically)
* [Ensure that a target is removed](#ensure-that-a-target-is-removed)
* [Include a subdirectory from another repository, like Oh My Zsh](#include-a-subdirectory-from-another-repository-like-oh-my-zsh)
* [Handle configuration files which are externally modified](#handle-configuration-files-which-are-externally-modified)
* [Keep data private](#keep-data-private)
* [Use Bitwarden to keep your secrets](#use-bitwarden-to-keep-your-secrets)
* [Use gopass to keep your secrets](#use-gopass-to-keep-your-secrets)
Expand Down Expand Up @@ -231,6 +232,36 @@ Disable Oh My Zsh auto-updates by setting `DISABLE_AUTO_UPDATE="true"` in
sync with chezmoi's source state. To update Oh My Zsh, re-run the `curl` and
`chezmoi import` commands above.

## Handle configuration files which are externally modified

Some programs modify their configuration files. When you next run `chezmoi
apply`, any modifications made by the program will be lost.

You can track changes to these files by replacing with a symlink back to a file
in your source directory, which is under version control. Here is a worked
example for VSCode's `settings.json` on Linux:

Copy the configuration file to your source directory:

cp ~/.config/Code/User/settings.json $(chezmoi source-path)

Tell chezmoi to ignore this file:

echo settings.json >> $(chezmoi source-path)/.chezmoiignore

Tell chezmoi that `~/.config/Code/User/settings.json` should be a symlink to the
file in your source directory:

mkdir -p $(chezmoi source-path)/.config/Code/User
echo -n "{{ .chezmoi.sourceDir }}/settings.json" > $(chezmoi source-path)/.config/Code/User/symlink_settings.json.tmpl

Apply the changes:

chezmoi apply -v

Now, when the program modifies its configuration file it will modify the file in
the source state instead.

## Keep data private

chezmoi automatically detects when files and directories are private when adding
Expand Down

0 comments on commit 1b655f9

Please sign in to comment.