#!/usr/bin/env bash function update_remote() { local repo="$1" for remote in $(git -C "$repo" remote 2>/dev/null) do local new_url="$(git -C "$repo" remote get-url "$remote" | sed -e 's|^https://FReenen:[0-9a-f]*@gitea.finnvanreenen.nl/|git@gitea.finnvanreenen.nl:|')" git -C "$repo" remote set-url "$remote" "$new_url" done return 1 } for repo in $(find $HOME/projects/ -type d -name '.git' | sed -e 's/ /%20;/g') do repo="$( echo "$repo" | sed -e 's/%20;/ /g' -e 's|/\.git$||' )" git -C "$repo" fetch --all 1>/dev/null \ || update_remote "$repo" \ || { echo "failt to fetch $repo" ; echo ; } changes="" staged="" unsgated="" git diff --cached --exit-code &>/dev/null || staged="staged" git diff --exit-code &>/dev/null || unsgated="unsgated" if [[ ! -z "$staged" && ! -z "$unstaged" ]] then changes="staged and unstaged changes" elif [[ ! -z "$unstaged" ]] then changes="unstaged changes" elif [[ ! -z "$staged" ]] then changes="staged changes" fi remote="" b=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') if [ "$b" != "" ] then behind=$(git rev-list HEAD...@{u} --ignore-submodules --count 2>/dev/null) ahead=$(git rev-list @{u}...HEAD --ignore-submodules --count 2>/dev/null) if [[ "$behind" > 0 && "$ahead" > 0 ]] then remote="merge with remote" elif [[ "$behind" > 0 ]] then remote="push to remote" elif [[ "$ahead" > 0 ]] then remote="pull from remote" fi fi if [[ ! -z "$changes" || ! -z "$remote" ]] then echo "# $repo" echo if [[ ! -z "$changes" && ! -z "$remote" ]] then echo "has $changes and has to $remote" elif [[ ! -z "$changes" ]] then echo "has $changes" elif [[ ! -z "$remote" ]] then echo "has to $remote" fi echo fi done