Last active
April 2, 2018 15:53
-
-
Save hmedkouri/dc9c0f4d1cbbf61b75384d794a346b27 to your computer and use it in GitHub Desktop.
zsh script to call a command on all git repositories under the current directory
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
#!/bin/zsh | |
# store the command and its paramters | |
CMD="$@" | |
# store the current dir | |
CUR_DIR=$(pwd) | |
# Let the person running the script know what's going on. | |
echo "\n\033[1mExecuting \033[0;32m'$CMD'\033[0m\033[1m against all repositories under $CUR_DIR ...\033[0m\n" | |
# Find all git repositories and execute the given command | |
for i in $(find . -name ".git" | sort -n | cut -c 3-); do | |
echo ""; | |
# We have to go to the .git parent directory to call the command | |
cd "$i"; | |
cd ..; | |
echo "\033[33m ${PWD##*/} \033[0m"; | |
# finally evaluate the command | |
eval $CMD; | |
# lets get back to the CUR_DIR | |
cd $CUR_DIR | |
done | |
echo "\n\033[32mComplete!\033[0m\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment