Last active
September 26, 2024 16:48
-
-
Save a-h-abid/ede05904ab924aa634e8659ed66f3516 to your computer and use it in GitHub Desktop.
Traverse across all directories in current path (excluding mentions) and run specified git command.
This file contains hidden or 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 bash | |
# set -x | |
# Check if any arguments are passed | |
if [[ $# -eq 0 ]]; then | |
echo "No git commands provided." | |
exit 1 | |
fi | |
gitCmds=("$@") | |
rootDir=$(pwd) | |
# Excluded directories (space-separated list) | |
EXCLUDED_DIRS=("dir1" "dir2") | |
# Get the list of directories, filter out the excluded ones & sort | |
DIRS=$(find . -maxdepth 1 -type d -printf "%f\n" | grep -v "^.$" | grep -vFf <(printf "%s\n" "${EXCLUDED_DIRS[@]}") | sort) | |
for dir in $DIRS; do | |
echo "================" | |
echo "Inside Dir: $dir" | |
cd "$rootDir/$dir" && git $gitCmds | |
echo | |
done | |
cd $rootDir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment