-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_cleanup.sh
More file actions
72 lines (56 loc) · 1.71 KB
/
project_cleanup.sh
File metadata and controls
72 lines (56 loc) · 1.71 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
set -euo pipefail
# Resolve script location (assumed to be in repo root or subdirectory)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Define repository root (adjust if script is in subdirectory)
REPO_ROOT="$SCRIPT_DIR"
echo "Scanning for virtual environment directories in:"
echo "$REPO_ROOT"
echo "---------------------------------------------"
# Safety checks
if [ ! -d "$REPO_ROOT" ]; then
echo "Error: Repository root does not exist. Aborting."
exit 1
fi
if [ -L "$REPO_ROOT" ]; then
echo "Error: Repository root is a symbolic link. Aborting."
exit 1
fi
case "$REPO_ROOT" in
""|"/"|"/home"|"/root")
echo "Error: Unsafe repository path detected. Aborting."
exit 1
;;
esac
# Find matching directories (non-recursive)
mapfile -t VENV_DIRS < <(find "$REPO_ROOT" -maxdepth 1 -type d -name ".venv*" -print)
if [ ${#VENV_DIRS[@]} -eq 0 ]; then
echo "No .venv* directories found. Nothing to clean."
exit 0
fi
echo "Found the following directories:"
for dir in "${VENV_DIRS[@]}"; do
echo " - $dir"
done
echo "---------------------------------------------"
# Confirm each directory individually
for dir in "${VENV_DIRS[@]}"; do
# Extra safety: ensure directory is exactly under repo root
if [[ "$(dirname "$dir")" != "$REPO_ROOT" ]]; then
echo "Skipping unexpected path: $dir"
continue
fi
# Ensure not a symlink
if [ -L "$dir" ]; then
echo "Skipping symbolic link: $dir"
continue
fi
read -r -p "Delete directory '$dir'? (y/N): " confirm
if [[ "$confirm" == "y" ]]; then
rm -rf -- "$dir"
echo "Deleted: $dir"
else
echo "Skipped: $dir"
fi
done
echo "Cleanup complete."