From 1201e6a4ccfeb35131e074dcc15a4b36066b8c03 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 11 Oct 2026 17:34:07 +0100 Subject: [PATCH] Feature: Sync dotfiles on system update update-system.sh now runs sync-dotfiles.sh first, which pulls the repo (fast-forward only) and re-stows it so both machines pick up config changes. Co-Authored-By: Claude Opus 5.5 --- .../quickshell/scripts/sync-dotfiles.sh | 50 +++++++++++++++++++ .../quickshell/scripts/update-system.sh | 6 ++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 dotfiles/.config/quickshell/scripts/sync-dotfiles.sh diff --git a/dotfiles/.config/quickshell/scripts/sync-dotfiles.sh b/dotfiles/.config/quickshell/scripts/sync-dotfiles.sh new file mode 100755 index 0000000..b706114 --- /dev/null +++ b/dotfiles/.config/quickshell/scripts/sync-dotfiles.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# Run by update-system.sh inside the update terminal, before the system +# update — pulls the dotfiles repo and re-stows it so both machines pick up +# config changes on every update. +# +# Never fails the update: a pull that can't fast-forward (local commits or +# uncommitted changes in the way) or a stow conflict just prints a warning +# and leaves things as they were, then the system update carries on. + +DOTFILES="$HOME/Projects/dotfiles" + +warn() { printf '\033[1;33m%s\033[0m\n' "$*"; } +info() { printf '\033[1;36m%s\033[0m\n' "$*"; } + +if [ ! -d "$DOTFILES/.git" ]; then + warn "Dotfiles repo not found at $DOTFILES — skipping." + exit 0 +fi + +info "Pulling dotfiles..." +# Fetch and merge separately so the warning says which one went wrong — the +# remote is SSH via Bitwarden's agent, so a failed fetch is almost always +# Bitwarden being closed or locked. +if ! git -C "$DOTFILES" fetch; then + warn "Couldn't reach the dotfiles remote — is Bitwarden open and unlocked? Skipping stow." + echo + exit 0 +fi +# --ff-only so a diverged branch never produces a surprise merge commit; +# sort that out by hand instead. +if ! git -C "$DOTFILES" merge --ff-only; then + warn "Couldn't fast-forward dotfiles (local changes or diverged branch) — skipping stow." + echo + exit 0 +fi + +if ! command -v stow &> /dev/null; then + warn "stow not installed — skipping." + exit 0 +fi + +info "Applying dotfiles with stow..." +# -R restows: drops links for files removed from the repo and adds new ones. +if stow -R -d "$DOTFILES" -t "$HOME" dotfiles; then + info "Dotfiles applied." +else + warn "stow hit a conflict — nothing was changed. Fix it and re-run:" + warn " stow -R -d $DOTFILES -t ~ dotfiles" +fi +echo diff --git a/dotfiles/.config/quickshell/scripts/update-system.sh b/dotfiles/.config/quickshell/scripts/update-system.sh index faccdff..c531175 100755 --- a/dotfiles/.config/quickshell/scripts/update-system.sh +++ b/dotfiles/.config/quickshell/scripts/update-system.sh @@ -58,5 +58,9 @@ fi # any output/errors with it. WAIT_PROMPT="echo; read -p 'Update finished — press Enter to close...'" -foot -T update bash -c "$BANNER; $CMD; $WAIT_PROMPT" +# Pull + re-stow the dotfiles first, so config changes from the other machine +# land alongside the package update. +SYNC="$(printf '%q' "$(dirname "$0")/sync-dotfiles.sh")" + +foot -T update bash -c "$BANNER; $SYNC; $CMD; $WAIT_PROMPT" notify-send -i "$iDIR/profile-pic.jpg" -u low "$LABEL" 'has been updated.'