-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.sh
More file actions
executable file
·72 lines (63 loc) · 2.1 KB
/
clean.sh
File metadata and controls
executable file
·72 lines (63 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Define base directory (default: current directory)
TARGET_DIR="${1:-.}"
# List of common cache directories to search for
# You can add or remove entries from this list based on your needs
CACHE_DIRS=(
"__pycache__" # Python
".pytest_cache" # Python (Pytest)
".mypy_cache" # Python (MyPy)
".cache" # Generic / Pip / Various tools
".ruff_cache" # Ruff Cache
".npm" # Node (local npm cache)
".parcel-cache" # Node (Parcel)
".eslintcache" # Node (ESLint)
".sass-cache" # Sass/SCSS
".terragrunt-cache" # Terraform/Terragrunt
"htmlcov" # Coverage reports
# "node_modules" # Uncomment if you want to nuke node_modules too (use with caution)
)
echo "--- Searching for cache directories in: $TARGET_DIR ---"
echo "Please wait, scanning..."
# Array to store found paths
FOUND_DIRS=()
# Loop to find directories matching the names in the list
for dir_name in "${CACHE_DIRS[@]}"; do
# 'find' searches recursively
# The while loop with IFS and -print0 handles filenames with spaces correctly
while IFS= read -r -d '' found; do
FOUND_DIRS+=("$found")
done < <(find "$TARGET_DIR" -type d -name "$dir_name" -print0 2>/dev/null)
done
# Check if anything was found
if [ ${#FOUND_DIRS[@]} -eq 0 ]; then
echo "No cache directories found."
exit 0
fi
# Display what was found
echo ""
echo "Found the following directories:"
echo "---------------------------------"
for path in "${FOUND_DIRS[@]}"; do
echo " -> $path"
done
echo "---------------------------------"
echo "Total directories found: ${#FOUND_DIRS[@]}"
echo ""
# Request confirmation
read -p "WARNING: Are you sure you want to permanently DELETE these directories? (y/N): " confirm
if [[ "$confirm" =~ ^[yY]$ ]]; then
echo ""
echo "Deleting..."
count=0
for path in "${FOUND_DIRS[@]}"; do
rm -rf "$path"
((count++))
echo "Deleted: $path"
done
echo ""
echo "Cleanup complete! $count directories removed."
else
echo ""
echo "Operation aborted. No files were touched."
fi