Creating an automatic .config (dotfiles) management system with chezmoi can make our lives a lot easier. Most of us already have our dotfiles in a github repo, so this module could make our experience a lot smoother.
Requirements:
We need a bash script that manages dotfiles with chezmoi:
1) pulls and updates the dotfiles every time the computer is turned on
2) pushes the changes to git every time the config files are updated (in ~/.config/chezmoi/chezmoi.toml set autoCommit and autoPush)
And a systemd service to do this automatically
(LLM-generated skeleton)
chezmoi-auto.service:
[Unit]
Description=Automatically update dotfiles with chezmoi
After=network-online.target
Exit immediately if a command exits with a non-zero status.
set -e
Pull the latest changes for your dotfiles from the source repository.
chezmoi update will fetch and apply the latest changes.
chezmoi update
Uncomment the following lines if your chezmoi configuration does not automatically commit and push changes,
and you would like this script to do so. Ensure you have configured git credentials correctly for non-interactive use.
cd $(chezmoi source-path)
git add .
git commit -m "Automatic update by chezmoi-auto.sh script"
git push
Notification example (optional, for desktop environments that support libnotify)
notify-send "Chezmoi Update" "Your dotfiles have been updated successfully."
### Using the module:
Bluebuild users could point this module to their dotfiles with:
chezmoi:
username: {username}
Setting up chezmoi the first time (from the docs):
chezmoi's install script can run chezmoi init for you by passing extra arguments to the newly installed chezmoi binary. If your dotfiles repo is github.com/$GITHUB_USERNAME/dotfiles then installing chezmoi, running chezmoi init, and running chezmoi apply can be done in a single line of shell:
$ sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply $GITHUB_USERNAME
If your dotfiles repo has a different name to dotfiles, or if you host your dotfiles on a different service, then see the reference manual for chezmoi init.
For setting up transitory environments (e.g. short-lived Linux containers) you can install chezmoi, install your dotfiles, and then remove all traces of chezmoi, including the source directory and chezmoi's configuration directory, with a single command:
$ sh -c "$(curl -fsLS get.chezmoi.io)" -- init --one-shot $GITHUB_USERNAME
### Relevant Chezmoi docs:
- [Concepts](https://www.chezmoi.io/reference/concepts)
- [Daily Operations Guide](https://www.chezmoi.io/user-guide/daily-operations/)
Idea from [ublue forums](https://universal-blue.discourse.group/t/dotfiles-and-custom-images/596)
Thanks so much for this project!
Context
Creating an automatic .config (dotfiles) management system with chezmoi can make our lives a lot easier. Most of us already have our dotfiles in a github repo, so this module could make our experience a lot smoother.
Requirements:
We need a bash script that manages dotfiles with chezmoi: 1) pulls and updates the dotfiles every time the computer is turned on 2) pushes the changes to git every time the config files are updated (in ~/.config/chezmoi/chezmoi.toml set autoCommit and autoPush) And a systemd service to do this automatically
(LLM-generated skeleton)
[Service] Type=oneshot ExecStart=/path/to/your/script/chezmoi-auto.sh
[Install] WantedBy=multi-user.target
!/usr/bin/env bash
Exit immediately if a command exits with a non-zero status.
set -e
Pull the latest changes for your dotfiles from the source repository.
chezmoi update will fetch and apply the latest changes.
chezmoi update
Uncomment the following lines if your chezmoi configuration does not automatically commit and push changes,
and you would like this script to do so. Ensure you have configured git credentials correctly for non-interactive use.
cd $(chezmoi source-path)
git add .
git commit -m "Automatic update by chezmoi-auto.sh script"
git push
Notification example (optional, for desktop environments that support libnotify)
notify-send "Chezmoi Update" "Your dotfiles have been updated successfully."
chezmoi: username: {username}
chezmoi's install script can run chezmoi init for you by passing extra arguments to the newly installed chezmoi binary. If your dotfiles repo is github.com/$GITHUB_USERNAME/dotfiles then installing chezmoi, running chezmoi init, and running chezmoi apply can be done in a single line of shell: $ sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply $GITHUB_USERNAME If your dotfiles repo has a different name to dotfiles, or if you host your dotfiles on a different service, then see the reference manual for chezmoi init. For setting up transitory environments (e.g. short-lived Linux containers) you can install chezmoi, install your dotfiles, and then remove all traces of chezmoi, including the source directory and chezmoi's configuration directory, with a single command: $ sh -c "$(curl -fsLS get.chezmoi.io)" -- init --one-shot $GITHUB_USERNAME