Skip to content

Instantly share code, notes, and snippets.

@hmedkouri
Last active April 2, 2018 15:53
Show Gist options
  • Save hmedkouri/dc9c0f4d1cbbf61b75384d794a346b27 to your computer and use it in GitHub Desktop.
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
#!/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