From 3cb52999e7b4005980f94579515f166101fd4460 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Sun, 10 May 2026 02:56:18 -0400 Subject: [PATCH] self-update: pull remote and re-exec if script changed before deploying --- setup_env.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/setup_env.sh b/setup_env.sh index fe39a14..d6570bf 100755 --- a/setup_env.sh +++ b/setup_env.sh @@ -119,8 +119,26 @@ deploy_nvim() { done } +# Pull latest from remote and re-exec if the script itself changed +self_update() { + if ! git -C "$(pwd)" rev-parse --is-inside-work-tree &>/dev/null; then + echo "Warning: not a git repo, skipping self-update" + return + fi + echo "Pulling latest from remote..." + local before after + before=$(git rev-parse HEAD) + git pull + after=$(git rev-parse HEAD) + if [ "$before" != "$after" ]; then + echo "setup_env.sh updated — re-running with latest version..." + exec "$0" "$@" + fi +} + # Main script main() { + self_update "$@" install_packages install_tpm install_vundle @@ -131,5 +149,5 @@ main() { echo "Setup complete! Please restart your shell or run 'source ~/.bashrc' for changes to take effect." } -main +main "$@"