#!/bin/sh columate() { _str="$1" _max_length=48 _length=$( printf "%s" $_str | wc -c) # Divide by 8, because that's the standard tabstop _tab_num=$(echo "($_max_length-$_length)/8" | bc -l ) _tabs="" # Create the tabs for _tab in $( seq $_tab_num ) ; do _tabs="$(printf "%s\t" $_tabs)" done # "Return" the tabs printf "%s" $_tabs } REPOS="$(find . -iname .git -type d | tail -n+2 | sed -e's/\/\.git$//' -e's_./__')" WD="$(pwd)" IFS=' ' echo '#!/bin/sh WD="$(pwd)" clone() { printf "\033[0mWorking dir: \033[1;34m%s\033[0;33m\n" $DIR if [ -d "$DIR" ] ; then cd $DIR git pull --ff-only origin master elif ! [ -d "$DIR" ] ; then mkdir -p "$DIR" cd "$DIR" git clone --depth=1 "$URL" . fi cd $WD printf "\033[0m" }' > setup.sh for _repo in $REPOS; do cd "$_repo" # I've probably made dangerous assumptions here, but whatever. URL="$(git remote --verbose| awk '{print $2}' | sort | uniq | head -n 1)" cd "$WD" _tabs="$(columate $_repo)" printf 'Added: \033[1;33m%s\033[0m%sURL: \033[1;34m%s\033[0m\n' \ $_repo $_tabs $URL printf 'DIR="%s"\nURL="%s"\nclone\n' $_repo $URL >> setup.sh done chmod +x setup.sh