Last active
February 9, 2017 15:13
-
-
Save ftorto/99b35a2f2de6397ad54b7d3f84e1c833 to your computer and use it in GitHub Desktop.
Apply a command to all sub git directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Git recursive | |
# Apply a command to all sub git directories | |
gr() { | |
rootpath=`pwd`/ | |
cmd=$* | |
if [ $# -eq 0 ]; then | |
echo "Multiline (Add empty line to end the input)" | |
cmd="" | |
while read line | |
do | |
# break if the line is empty | |
[ -z "$line" ] && break | |
cmd+="$line;" | |
done | |
fi | |
for d in `find . -maxdepth 2 -type d -name .git | sed 's@./@@; s@/.git@@'` | |
do | |
# Separator | |
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' _ | |
# Path | |
echo -e "\033[2;37m${rootpath}\033[1;32m$d\033[0m" | |
# Apply command | |
cd $d > /dev/null; | |
eval $cmd | |
cd - > /dev/null; | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment