Skip to content

Instantly share code, notes, and snippets.

@marcelkornblum
Created October 27, 2014 16:33
Show Gist options
  • Save marcelkornblum/5df851b7ac130eb18490 to your computer and use it in GitHub Desktop.
Save marcelkornblum/5df851b7ac130eb18490 to your computer and use it in GitHub Desktop.
Post-checkout git hook for local PY coding. It will remove all .pyc files after a checkout, which can cause problems otherwise. Put this code into ~/.git/hooks/post-checkout and then chmod +x ~/.git/hooks/post-checkout from this directory.
#!/usr/bin/env bash
# Delete .pyc files and empty directories from root of project
cd ./$(git rev-parse --show-cdup)
# Clean-up
find . -name ".DS_Store" -delete
NUM_PYC_FILES=$( find . -name "*.pyc" | wc -l | tr -d ' ' )
if [ $NUM_PYC_FILES -gt 0 ]; then
find . -name "*.pyc" -delete
printf "\e[00;31mDeleted $NUM_PYC_FILES .pyc files\e[00m\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment