feat(chezmoi): Allow specifying branch for chezmoi init (#357)
* feat: allow specifying branch for `chezmoi init` * fix: don't assume the default branch is `main` * fix: get rid of `main` reference in the README
This commit is contained in:
parent
be9f17c96e
commit
e328da9497
3 changed files with 23 additions and 15 deletions
|
|
@ -3,13 +3,13 @@
|
|||
The `chezmoi` module takes care of installing, initializing and updating your dotfiles.
|
||||
Each feature can be enabled or disabled individually.
|
||||
|
||||
Installation of the `chezmoi` binary happens at build time and is done by downloading the `amd64` binary from the latest release to `/usr/bin/chezmoi`.
|
||||
Installation of the `chezmoi` binary happens at build time and is done by downloading the `amd64` binary from the latest release to `/usr/bin/chezmoi`.
|
||||
This can be disabled by setting `install` to false. (defaults: true)
|
||||
|
||||
Choose how `chezmoi` handles conflicting files with `file-conflict-policy`.
|
||||
Choose how `chezmoi` handles conflicting files with `file-conflict-policy`.
|
||||
The following values are valid:
|
||||
`"skip"` Will not take any action if the file has changed from what is in your dotfiles repository.
|
||||
This executes `chezmoi update --no-tty --keep-going` under the hood.
|
||||
`"skip"` Will not take any action if the file has changed from what is in your dotfiles repository.
|
||||
This executes `chezmoi update --no-tty --keep-going` under the hood.
|
||||
`"replace"` Will overwrite the file if it has changed from what is in your dotfiles repository.
|
||||
This executes `chezmoi update --no-tty --force` under the hood.
|
||||
|
||||
|
|
@ -17,11 +17,11 @@ See `chezmoi`s documentation for [`--no-tty`](https://www.chezmoi.io/reference/c
|
|||
|
||||
A systemd user service is installed that will initialize a `chezmoi` repository on chezmoi's default path (`~/.local/share/chezmoi`) for any user when it logs in, or at boot if it has lingering enabled.
|
||||
The service will only run if `~/.local/share/chezmoi` does not exist.
|
||||
Set `repository` to the URL of your dotfiles repository. (eg. `repository: https://example.org/user/dotfiles`)
|
||||
Set `repository` to the URL of your dotfiles repository. (eg. `repository: https://example.org/user/dotfiles`). You can also set `branch` if you want to use a branch different than the default.
|
||||
:::note
|
||||
The value of `repository` will be passed directly to `chezmoi init --apply ${repository}`.
|
||||
The value of `repository` and `branch` will be passed directly to `chezmoi init --apply ${repository} --branch ${branch}`.
|
||||
See the [`chezmoi init` documentation](https://www.chezmoi.io/reference/commands/init/) for detailed syntax.
|
||||
:::
|
||||
:::
|
||||
Set `disable-init` to `true` if you do not want to install the init service.
|
||||
|
||||
:::caution
|
||||
|
|
@ -46,10 +46,10 @@ sudo systemctl enable --user chesmoi-init.service chezmoi-update.timer
|
|||
To turn on lingering for a given user, run the following command with sudo:
|
||||
|
||||
:::note
|
||||
By default, any systemd units in a user's namespace will run after the user logs in, and will close after the user closes their last session.
|
||||
By default, any systemd units in a user's namespace will run after the user logs in, and will close after the user closes their last session.
|
||||
When you enable lingering for a user, that user's units will run at boot and will continue running even if the user has no active sessions.
|
||||
|
||||
If your dotfiles only contain things used by humans, such as cosmetic settings and aliases, you shouldn't need this.
|
||||
If your dotfiles only contain things used by humans, such as cosmetic settings and aliases, you shouldn't need this.
|
||||
If you understand the above implications, and decide you need this feature, you can enable it with the following command, after installation:
|
||||
:::
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,13 @@ fi
|
|||
|
||||
# The repository with your chezmoi dotfiles. (default: null)
|
||||
DOTFILE_REPOSITORY=$(echo "$1" | yq -I=0 ".repository") # (string)
|
||||
# The chezmoi repository branch to use.
|
||||
DOTFILE_BRANCH=$(echo "$1" | yq -I=0 ".branch")
|
||||
if [[ -n ${DOTFILE_BRANCH} ]]; then
|
||||
INIT_BRANCH_FLAG="--branch ${DOTFILE_BRANCH}"
|
||||
else
|
||||
INIT_BRANCH_FLAG=""
|
||||
fi
|
||||
|
||||
# If true, chezmoi services will be enabled for all logged in users, and users with lingering enabled. (default: true)
|
||||
# If false, chezmoi services will not be enabled for any users, but can be enabled manually, after installation.
|
||||
|
|
@ -85,7 +92,6 @@ if [[ (-z $DOTFILE_REPOSITORY || $DOTFILE_REPOSITORY == "null") && $DISABLE_INIT
|
|||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "Checking if /usr/bin/chezmoi exists"
|
||||
if [ -e /usr/bin/chezmoi ]; then
|
||||
echo "chezmoi binary already exists, no need to redownload it"
|
||||
|
|
@ -104,18 +110,17 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [[ $DISABLE_INIT == false ]]; then
|
||||
# Write the service to initialize Chezmoi, and insert the repo url in the file
|
||||
echo "Writing init service to user unit directory"
|
||||
cat >>/usr/lib/systemd/user/chezmoi-init.service <<EOF
|
||||
[Unit]
|
||||
Description=Initializes Chezmoi if directory is missing
|
||||
|
||||
|
||||
# This service will not execute for a user with an existing chezmoi directory
|
||||
ConditionPathExists=!%h/.local/share/chezmoi/.git/
|
||||
[Service]
|
||||
ExecStart=/usr/bin/chezmoi init --apply ${DOTFILE_REPOSITORY}
|
||||
ExecStart=/usr/bin/chezmoi init --apply ${DOTFILE_REPOSITORY} ${INIT_BRANCH_FLAG}
|
||||
Type=oneshot
|
||||
|
||||
[Install]
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ model ChezmoiModule {
|
|||
/** Git repository to initialize. */
|
||||
repository: string;
|
||||
|
||||
/** Git branch of the chezmoi repository. */
|
||||
branch?: string = "";
|
||||
|
||||
/** Whether to enable the modules services globally for all users, if false users need to enable services manually. */
|
||||
"all-users"?: boolean = true;
|
||||
|
||||
|
|
@ -19,7 +22,7 @@ model ChezmoiModule {
|
|||
|
||||
/** Dotfile updates will wait this long after a boot before running. */
|
||||
"wait-after-boot"?: string = "5m";
|
||||
|
||||
|
||||
/** Disable the service that initializes `repository` on users that are logged in or have linger enabled UI. */
|
||||
"disable-init"?: boolean = false;
|
||||
|
||||
|
|
@ -28,4 +31,4 @@ model ChezmoiModule {
|
|||
|
||||
/** What to do when file different that exists on your repo is has been changed or exists locally. Accepts "skip" or "replace". */
|
||||
"file-conflict-policy"?: "skip" | "replace" = "skip";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue