-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup-all-repos.sh
More file actions
executable file
·134 lines (112 loc) · 3.03 KB
/
Copy pathsetup-all-repos.sh
File metadata and controls
executable file
·134 lines (112 loc) · 3.03 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
# Batch setup Agent Engineering Handbook for all git repos under a parent directory.
#
# Usage:
# ./setup-all-repos.sh [OPTIONS] [parent-workspace]
#
# Examples:
# ./setup-all-repos.sh ~/code
# ./setup-all-repos.sh -S -l --ensure-gitignore ~/code
set -euo pipefail
IFS=$'\n\t'
if [[ -t 1 ]]; then
RED=$'\033[0;31m'
GREEN=$'\033[0;32m'
YELLOW=$'\033[0;33m'
BLUE=$'\033[0;34m'
CYAN=$'\033[0;36m'
NC=$'\033[0m'
else
RED= GREEN= YELLOW= BLUE= CYAN= NC=
fi
usage() {
cat << 'EOF'
Usage: setup-all-repos.sh [OPTIONS] [parent-workspace]
Finds git repos under parent-workspace (max depth 2) and runs setup-workspace.sh for each.
Options (passed through to setup-workspace.sh):
-S, --symlink-all
-l, --lightweight
-f, --full
--ensure-gitignore
-h, --help
Examples:
./setup-all-repos.sh -S -l ~/code
./setup-all-repos.sh -S -f --ensure-gitignore ~/code
EOF
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SETUP_SCRIPT="${SCRIPT_DIR}/setup-workspace.sh"
if [[ ! -f "$SETUP_SCRIPT" ]]; then
echo "${RED}Error: setup script not found: $SETUP_SCRIPT${NC}" >&2
exit 1
fi
PARENT_WORKSPACE="$(pwd)"
SETUP_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help)
usage
exit 0
;;
-S | --symlink-all | -l | --lightweight | -f | --full | --ensure-gitignore)
SETUP_ARGS+=("$1")
shift
;;
-*)
echo "${RED}Error: Unknown option: $1${NC}" >&2
usage >&2
exit 1
;;
*)
PARENT_WORKSPACE="$1"
shift
;;
esac
done
if [[ ! -d "$PARENT_WORKSPACE" ]]; then
echo "${RED}Error: Parent workspace directory not found: $PARENT_WORKSPACE${NC}" >&2
exit 1
fi
PARENT_WORKSPACE="$(cd "$PARENT_WORKSPACE" && pwd)"
echo "${BLUE}Setting up Cursor rules for repos under:${NC}"
echo "${CYAN}${PARENT_WORKSPACE}${NC}"
echo ""
repos=()
while IFS= read -r -d '' git_dir; do
repos+=("$(dirname "$git_dir")")
done < <(find "$PARENT_WORKSPACE" -maxdepth 2 -type d -name ".git" -print0)
if [[ ${#repos[@]} -eq 0 ]]; then
echo "${YELLOW}No git repositories found.${NC}"
exit 0
fi
echo "${GREEN}Found ${#repos[@]} repository(ies).${NC}"
echo "${YELLOW}Press Enter to continue, or Ctrl+C to cancel...${NC}"
read -r
success_count=0
skip_count=0
error_count=0
for repo_dir in "${repos[@]}"; do
repo_rel_path="${repo_dir#$PARENT_WORKSPACE/}"
echo -n "${BLUE}[${repo_rel_path}]${NC} "
# Skip if already present (symlink or dir)
if [[ -L "${repo_dir}/.cursor/rules" ]] || [[ -d "${repo_dir}/.cursor/rules" ]]; then
echo "${YELLOW}Already set up, skipping.${NC}"
((skip_count++))
continue
fi
if "$SETUP_SCRIPT" "${SETUP_ARGS[@]}" "$repo_dir" > /dev/null 2>&1; then
echo "${GREEN}✓ Setup complete${NC}"
((success_count++))
else
echo "${RED}✗ Setup failed${NC}"
((error_count++))
fi
done
echo ""
echo "${GREEN}Setup Summary:${NC}"
echo " ${GREEN}✓ Success:${NC} $success_count"
echo " ${YELLOW}⊘ Skipped:${NC} $skip_count"
echo " ${RED}✗ Errors:${NC} $error_count"
if [[ $error_count -gt 0 ]]; then
exit 1
fi