Last active
March 1, 2025 17:12
-
-
Save choutianxius/4072192f24fcf71e06340d2856428cd2 to your computer and use it in GitHub Desktop.
Simple `pyclean` on MacOS
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/zsh | |
function usage() { | |
cat << END | |
pyclean (custom shell script impl) | |
Description: | |
Recursively finds and deletes Python bytecode files (*.pyc, *.pyo) and | |
__pycache__ directories within the specified directories. | |
Usage: | |
pyclean [directories...] | |
[directories ...] One or more directories where the cleanup should be performed. | |
Example: | |
pyclean /path/to/project1 /path/to/project2 | |
Options: | |
-h, --help Display this help message and exit. | |
END | |
} | |
if [ "$#" -eq 0 ]; then | |
usage | |
exit 0 | |
fi | |
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | |
usage | |
exit 0 | |
fi | |
for dir in "$@"; do | |
if [ -d "$dir" ]; then | |
echo "Cleaning Python cache files in: $dir" | |
find "$dir" -type f -name '*.py[co]' -delete -o -type d -name '__pycache__' -delete | |
else | |
echo "Warning: $dir is not a valid directory" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment