Last active
December 12, 2015 10:09
-
-
Save glyphobet/4757316 to your computer and use it in GitHub Desktop.
self-installing git-hook to remove stale *.pyc files and empty directories when switching branches.
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/bash | |
mybasename=`basename $0` | |
if [ ! -e .git/hooks/${mybasename} ] ; then | |
ln -s ../../git-hooks/${mybasename} .git/hooks/${mybasename} | |
fi | |
if [ $3 ] && [ $3 -eq '1' ] ; then | |
# Start from the repository root. | |
pushd ./$(git rev-parse --show-cdup) > /dev/null | |
# Delete .pyc files | |
find . -name "*.pyc" -delete 2>&1 > /dev/null & | |
# Delete empty directories | |
find . -type d -empty -delete | |
# Go back to wherever you were | |
popd > /dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment