From d964af18cbd6d6ffdd70ddb180289094dff6fe56 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Sun, 10 May 2026 02:17:55 -0400 Subject: [PATCH] migrate existing .bashrc_local and .bashrc_paths into repo on setup --- setup_env.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/setup_env.sh b/setup_env.sh index a96f6ad..211417e 100755 --- a/setup_env.sh +++ b/setup_env.sh @@ -52,15 +52,35 @@ create_symlink() { ln -s "$target" "$link_name" } +# Like create_symlink, but if the dotfiles/ target doesn't exist yet and the +# home file is a real file (not a symlink), migrate it into the repo first. +# Used for gitignored files (.bashrc_local, .bashrc_paths) so existing machine +# config is preserved rather than buried in a .backup file. +migrate_and_link() { + local target=$1 + local link_name=$2 + + if [[ ! -e "$target" && -f "$link_name" && ! -L "$link_name" ]]; then + echo "Migrating existing $link_name -> $target" + cp "$link_name" "$target" + fi + + create_symlink "$target" "$link_name" +} + # Deploy configuration files as symlinks deploy_configs() { echo "Deploying configuration files as symlinks..." - CONFIG_DIR="$(pwd)/dotfiles" # Use the local 'dotfiles' directory in the repo + CONFIG_DIR="$(pwd)/dotfiles" - for config in .bashrc .bashrc_local .bashrc_paths .vimrc .gitconfig .pspgconf .psqlrc .tmux.conf ; do + for config in .bashrc .vimrc .gitconfig .pspgconf .psqlrc .tmux.conf ; do create_symlink "$CONFIG_DIR/$config" ~/$config done + for config in .bashrc_local .bashrc_paths ; do + migrate_and_link "$CONFIG_DIR/$config" ~/$config + done + echo "Sourcing .bashrc..." source ~/.bashrc }