Created
September 1, 2015 02:17
-
-
Save rstacruz/f8d2642cbcc3756ca921 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env sh | |
pwd="`pwd`" | |
dirs=* | |
code=0 | |
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in | |
-q | --quiet ) | |
quiet=1 | |
;; | |
-i | --ignore-errors ) | |
ignoreerrors=1 | |
;; | |
-h | --help ) | |
echo "Usage: multi [-qi] <command>" | |
echo "runs a command in all child directories." | |
echo "" | |
echo "Options:" | |
echo " -q, --quiet supress echoing of commands" | |
echo " -i, --ignore-errors don't care about errors" | |
echo "" | |
echo "Example:" | |
echo " multi git push" | |
echo " multi -i git commit -m update" | |
exit | |
esac; shift; done | |
if [[ "$1" == "--" ]]; then shift; fi | |
if [ "$ignoreerrors" != "1" ]; then | |
set -o errexit | |
fi | |
for dir in $dirs; do | |
if [ -d $dir ]; then | |
if [ "$quiet" != "1" ]; then echo "\n\033[34m$dir\033[32m → $@\033[0m"; fi | |
cd $dir && $@ 2>&1 | |
result=$? | |
if [ "$ignoreerrors" = "1" ]; then result=0; fi | |
if [ "$result" != "0" ]; then code=$result; fi | |
cd $pwd | |
fi | |
done | |
exit $code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment