Skip to content

Instantly share code, notes, and snippets.

@thetemplateblog
Forked from mslinn/update.sh
Created May 7, 2019 19:46
Show Gist options
  • Save thetemplateblog/c79b77e624013d954573cef409c4726a to your computer and use it in GitHub Desktop.
Save thetemplateblog/c79b77e624013d954573cef409c4726a to your computer and use it in GitHub Desktop.
Bash Script to Update all Git Directories Below Current Directory or Specified Directory
#!/bin/bash
# From ScalaCourses.com Introduction to Play Framework with Scala course
# Update all git directories below current directory or specified directory
# Skips directories that contain a file called .ignore
#
# Using printf insteach of echo -e for Mac OS
# See http://stackoverflow.com/questions/4435853/echo-outputs-e-parameter-in-bash-scripts-how-can-i-prevent-this
# Use ANSI colors if possible; see https://unix.stackexchange.com/a/10065/142869
# check if stdout is a terminal
if test -t 1; then
# see if it supports colors
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
HIGHLIGHT="\e[01;34m"
NORMAL='\e[00m'
fi
fi
function update {
local d="$1"
if [ -d "$d" ]; then
#echo "Looking for $d/.ignore"
if [ -e "$d/.ignore" ]; then
printf "%b\n" "\n${HIGHLIGHT}Ignoring $d${NORMAL}"
else
cd "$d" > /dev/null
if [ -d ".git" ]; then
printf "%b\n" "\n${HIGHLIGHT}Updating `pwd`$NORMAL"
git pull
elif [ ! -d .svn ] && [ ! -d CVS ]; then
scan *
fi
cd .. > /dev/null
fi
fi
#echo "Exiting update: pwd=`pwd`"
}
function scan {
#echo "`pwd`"
#echo "About to scan $*"
for x in $*; do
update "$x"
done
}
function updater {
if [ "$1" != "" ]; then cd "$1" > /dev/null; fi
printf "%b\n" "${HIGHLIGHT}Scanning ${PWD}${NORMAL}"
scan *
}
if [ "$1" == "" ]; then
updater
else
for dir in "$@"; do
updater "$dir"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment