Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rm-gitignore script #3 #30

Closed
wants to merge 19 commits into from
21 changes: 21 additions & 0 deletions scripts/rm-gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,24 @@

# Removes all files written in .gitignore of any git repository (multiple) present inside current directory
# To find list of all git repos inside current directory you can use: "find . -name .git -type d -prune"
# Find all git repositories in the current directory
find . -type f -name .gitignore | while read -r gitignore;
do
# Navigate to the directory containing the .gitignore file
cd "$(dirname "$gitignore")" || continue

echo "Removing files listed in .gitignore for directory: $(pwd)"

# Read the .gitignore file and remove files listed in it
while IFS= read -r pattern;
do
# Use grep to filter out comment lines and empty lines
if [[ ! "$pattern" =~ ^(\s*#|\s*$) ]];
then
# Remove files matching patterns in .gitignore
rm -rf -- $pattern
fi
done < "$gitignore"

echo "Files removed."
done