Skip to content

Instantly share code, notes, and snippets.

@glyphobet
Last active December 12, 2015 10:09
Show Gist options
  • Save glyphobet/4757316 to your computer and use it in GitHub Desktop.
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.
#!/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