Skip to content

Instantly share code, notes, and snippets.

@choutianxius
Last active March 1, 2025 17:12
Show Gist options
  • Save choutianxius/4072192f24fcf71e06340d2856428cd2 to your computer and use it in GitHub Desktop.
Save choutianxius/4072192f24fcf71e06340d2856428cd2 to your computer and use it in GitHub Desktop.
Simple `pyclean` on MacOS
#!/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