Last active
March 20, 2017 11:43
-
-
Save miebach/7391024 to your computer and use it in GitHub Desktop.
post-checkout hook for python pyc files on git. See http://stackoverflow.com/questions/1504724/a-git-hook-for-whenever-i-change-branches and http://codeinthehole.com/writing/a-useful-git-post-checkout-hook-for-python-repos/
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
#!/usr/bin/env bash | |
# gist at https://gist.github.com/miebach/7391024 | |
# save this file to .git/hooks/post-checkout | |
# and also to .git/hooks/post-merge | |
# and make it executable | |
# Delete .pyc files and empty directories from root of project | |
cd ./$(git rev-parse --show-cdup) | |
# Clean-up | |
find . -name ".DS_Store" -type f | xargs rm -f | |
NUM_PYC_FILES=$( find . -name "*.pyc" -type f | wc -l | tr -d ' ' ) | |
if [ $NUM_PYC_FILES -gt 0 ]; then | |
find . -name "*.pyc" -type f | xargs rm -f | |
printf "\e[00;31mDeleted $NUM_PYC_FILES .pyc files\e[00m\n" | |
fi | |
NUM_EMPTY_DIRS=$( find . -type d -empty | wc -l | tr -d ' ' ) | |
if [ $NUM_EMPTY_DIRS -gt 0 ]; then | |
find . -type d -empty -type f | xargs rm -f | |
printf "\e[00;31mDeleted $NUM_EMPTY_DIRS empty directories\e[00m\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment