Skip to content

Instantly share code, notes, and snippets.

@tomchuk
Created February 25, 2015 19:56
Show Gist options
  • Select an option

  • Save tomchuk/9684ad61f5bcb2b485ad to your computer and use it in GitHub Desktop.

Select an option

Save tomchuk/9684ad61f5bcb2b485ad to your computer and use it in GitHub Desktop.
Post Checkout Hook
#!/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
NUM_PYCACHE_FILES=$( find . -name "__pycache__" | wc -l | tr -d ' ' )
if [ $NUM_PYCACHE_FILES -gt 0 ]; then
find . -name "__pycache__" -delete
printf "\e[00;31mDeleted $NUM_PYCACHE_FILES __pycache__ dirs\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 -delete
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