Skip to content

Commit

Permalink
Add how to for managing part of a file
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 13, 2021
1 parent 802c6ca commit a706029
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [Manage different types of file](#manage-different-types-of-file)
* [Have chezmoi create a directory, but ignore its contents](#have-chezmoi-create-a-directory-but-ignore-its-contents)
* [Ensure that a target is removed](#ensure-that-a-target-is-removed)
* [Manage part, but not all, of a file](#manage-part-but-not-all-of-a-file)
* [Populate `~/.ssh/authorized_keys` with your public SSH keys from GitHub](#populate-sshauthorized_keys-with-your-public-ssh-keys-from-github)
* [Integrate chezmoi with your editor](#integrate-chezmoi-with-your-editor)
* [Configure VIM to run `chezmoi apply` whenever you save a dotfile](#configure-vim-to-run-chezmoi-apply-whenever-you-save-a-dotfile)
Expand Down Expand Up @@ -190,6 +191,25 @@ dry-run mode beforehand to see what would be removed:
on different machines. Negative matches (patterns prefixed with a `!`) or
targets listed in `.chezmoiignore` will never be removed.

### Manage part, but not all, of a file

chezmoi, by default, manages whole files, but there are two ways to manage just
parts of a file.

Firstly, a `modify_` script receives the current contents of the file on the
standard input and chezmoi reads the target contents of the file from the
script's standard output. This can be used to change parts of a file, for
example using `sed`. Note that if the file does not exist then the standard
input to the `modify_` script will be empty and it is the script's
responsibility to write a complete file to the standard output.

Secondly, if only a small part of the file changes then consider using a
template to re-generate the full contents of the file from the current state.
For example, Kubernetes configurations include a current context that can be
substituted with:

current-context: {{ output "kubectl" "config" "current-context" | trim }}

### Populate `~/.ssh/authorized_keys` with your public SSH keys from GitHub

chezmoi can retrieve your public SSH keys from GitHub, which can be useful for
Expand Down

0 comments on commit a706029

Please sign in to comment.