From 63a194855101a61e3a51ef4734d9c39f49a8aa0b Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Tue, 27 Aug 2024 20:52:24 +0200 Subject: [PATCH] feat: Add push command to automate pushing changes to all remotes --- bin/actions/push.sh | 29 +++++++++++++++++++++++++++++ bin/dotf | 8 ++++++++ 2 files changed, 37 insertions(+) create mode 100755 bin/actions/push.sh diff --git a/bin/actions/push.sh b/bin/actions/push.sh new file mode 100755 index 0000000..0f69a85 --- /dev/null +++ b/bin/actions/push.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env zsh + +source $HOME/dotfiles/bin/helpers/functions.sh + +# Push all changes from $HOME/dotfiles to ALL remotes in $HOME/dotfiles/.git/config +push_all() { + # Get all remotes from the .git/config file + remotes=($(cat $HOME/dotfiles/.git/config | grep url | awk '{print $3}')) + + printfe "%s\n" "cyan" "Pushing all changes to all remotes..." + + # For each remote, push all changes + for remote in $remotes; do + printfe "%s" "green" " - Pushing to [" + printfe "%s" "blue" "$remote" + printfe "%s\n" "green" "]..." + + result=$(git -C $HOME/dotfiles push $remote 2>&1) + + # If the push failed, print an error + if [ $? -ne 0 ]; then + printfe "%s\n" "red" " - Failed to push to $remote:" + printfe "%s\n" "red" " $result" + continue + fi + done +} + +push_all diff --git a/bin/dotf b/bin/dotf index fc34474..abb47cb 100755 --- a/bin/dotf +++ b/bin/dotf @@ -23,6 +23,10 @@ secrets() { $HOME/dotfiles/bin/actions/secrets.sh $@ } +push() { + $HOME/dotfiles/bin/actions/push.sh $@ +} + ensure_git_hooks() { # If ~/dotfiles/.git/hooks is a symlink, skip this if [[ -L ~/dotfiles/.git/hooks ]]; then @@ -50,6 +54,10 @@ case $1 in logo update $@ ;; + "push") + logo continue + push $@ + ;; "status") logo continue status $@