Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .chezmoiscripts/run_onchange_after_setup-shared-symlinks.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ symlink_to_home() {
done
}

# ========================================
# Function: Persist a ~/.config/<name> directory via /shared/.config
# ========================================
# Symlinks ~/.config/<name> -> /shared/.config/<name> so its contents
# (credentials, caches, etc.) survive workspace rebuilds. A pre-existing real
# directory is migrated into the shared location once, then backed up.
symlink_shared_config() {
local name="$1"
local shared="/shared/.config/$name"
local target="$HOME/.config/$name"

mkdir -p "$shared"
# Migrate a pre-existing real directory into the shared location once. Only
# swap it for the symlink if the copy fully succeeds — otherwise leave the
# real config in place and bail, so we never symlink to an incomplete copy
# (which would leave the real data only in the backup).
if [ -e "$target" ] && [ ! -L "$target" ]; then
if ! cp -a "$target/." "$shared/"; then
echo "⚠ Could not migrate ~/.config/$name into $shared; leaving real config in place" >&2
return 0
fi
local backup="${shared}.backup_$(date +%Y%m%d_%H%M%S)"
mv "$target" "$backup"
echo "✓ Migrated existing ~/.config/$name into $shared (backup: $backup)"
fi
Comment thread
fx marked this conversation as resolved.
mkdir -p "$HOME/.config"
ln -sfn "$shared" "$target"
echo "✓ ~/.config/$name -> $shared"
}

# ========================================
# CODER WORKSPACE SETUP
# ========================================
Expand Down Expand Up @@ -85,5 +115,15 @@ if [ "$CODER" = "true" ]; then
echo "✓ GitHub CLI symlinked to $GH_SHARED_CONFIG"
fi

# Persist selected ~/.config/* directories to /shared/.config so their
# contents (credentials, caches, etc.) survive workspace rebuilds.
# Add directory names here to share more config folders.
SHARED_CONFIG_DIRS=(
gcloud
)
for cfg in "${SHARED_CONFIG_DIRS[@]}"; do
symlink_shared_config "$cfg"
done

fi
{{ end -}}
Loading