|
6 | 6 | # Reads rules from .claude/rules/ and generates: |
7 | 7 | # - Slash commands in .claude/commands/ |
8 | 8 | # - Skills in .claude/skills/*/SKILL.md |
| 9 | +# |
| 10 | +# Compatible with Bash 3.2+ (default on macOS) |
9 | 11 | # ============================================================================= |
10 | 12 |
|
11 | 13 | set -e |
@@ -34,8 +36,11 @@ RULES_DIR="$CLAUDE_DIR/rules" |
34 | 36 | COMMANDS_DIR="$CLAUDE_DIR/commands" |
35 | 37 | SKILLS_DIR="$CLAUDE_DIR/skills" |
36 | 38 |
|
37 | | -# Associative arrays for rules and skills |
38 | | -declare -A RULES |
| 39 | +# Use temp directory for storing rules (Bash 3.2 compatible) |
| 40 | +TEMP_RULES_DIR=$(mktemp -d) |
| 41 | +trap 'rm -rf "$TEMP_RULES_DIR"' EXIT |
| 42 | + |
| 43 | +# Array for available skills |
39 | 44 | declare -a AVAILABLE_SKILLS |
40 | 45 |
|
41 | 46 | # ----------------------------------------------------------------------------- |
@@ -70,7 +75,8 @@ load_rules() { |
70 | 75 | while IFS= read -r -d '' md_file; do |
71 | 76 | local rule_id |
72 | 77 | rule_id=$(basename "$md_file" .md) |
73 | | - RULES["$rule_id"]=$(cat "$md_file") |
| 78 | + # Store rule content in temp file instead of associative array |
| 79 | + cat "$md_file" > "$TEMP_RULES_DIR/$rule_id" |
74 | 80 | log_success "Loaded $category/$(basename "$md_file")" |
75 | 81 | ((rule_count++)) || true |
76 | 82 | done < <(find "$category_dir" -maxdepth 1 -name "*.md" -print0 2>/dev/null) |
@@ -236,35 +242,31 @@ build_commands() { |
236 | 242 | local command_count=0 |
237 | 243 |
|
238 | 244 | while IFS='|' read -r cmd_name description model inject_skills rules_list; do |
239 | | - local output_parts=() |
| 245 | + local command_file="$COMMANDS_DIR/${cmd_name}.md" |
240 | 246 |
|
241 | | - # Add frontmatter |
242 | | - output_parts+=("---") |
243 | | - output_parts+=("description: $description") |
244 | | - output_parts+=("model: $model") |
245 | | - output_parts+=("---") |
| 247 | + # Write frontmatter |
| 248 | + { |
| 249 | + echo "---" |
| 250 | + echo "description: $description" |
| 251 | + echo "model: $model" |
| 252 | + echo "---" |
| 253 | + } > "$command_file" |
246 | 254 |
|
247 | 255 | # Add rules content |
248 | 256 | for rule_id in $rules_list; do |
249 | | - if [[ -n "${RULES[$rule_id]}" ]]; then |
250 | | - output_parts+=("${RULES[$rule_id]}") |
251 | | - output_parts+=("") |
| 257 | + if [[ -f "$TEMP_RULES_DIR/$rule_id" ]]; then |
| 258 | + cat "$TEMP_RULES_DIR/$rule_id" >> "$command_file" |
| 259 | + echo "" >> "$command_file" |
252 | 260 | else |
253 | 261 | log_warning "Rule '$rule_id' not found" |
254 | 262 | fi |
255 | 263 | done |
256 | 264 |
|
257 | 265 | # Add skills section if needed |
258 | 266 | if [[ "$inject_skills" == "True" || "$inject_skills" == "true" ]]; then |
259 | | - local skills_section |
260 | | - skills_section=$(format_skills_section) |
261 | | - [[ -n "$skills_section" ]] && output_parts+=("$skills_section") |
| 267 | + format_skills_section >> "$command_file" |
262 | 268 | fi |
263 | 269 |
|
264 | | - # Write command file |
265 | | - local command_file="$COMMANDS_DIR/${cmd_name}.md" |
266 | | - printf "%s\n" "${output_parts[@]}" > "$command_file" |
267 | | - |
268 | 270 | if [[ "$inject_skills" == "True" || "$inject_skills" == "true" ]]; then |
269 | 271 | log_success "Generated ${cmd_name}.md (with skills)" |
270 | 272 | else |
@@ -296,13 +298,13 @@ build_skills() { |
296 | 298 | local rule_id |
297 | 299 | rule_id=$(basename "$md_file" .md) |
298 | 300 |
|
299 | | - [[ -z "${RULES[$rule_id]}" ]] && continue |
| 301 | + [[ ! -f "$TEMP_RULES_DIR/$rule_id" ]] && continue |
300 | 302 |
|
301 | 303 | local skill_dir="$SKILLS_DIR/$rule_id" |
302 | 304 | mkdir -p "$skill_dir" |
303 | 305 |
|
304 | 306 | local skill_file="$skill_dir/SKILL.md" |
305 | | - echo "${RULES[$rule_id]}" > "$skill_file" |
| 307 | + cat "$TEMP_RULES_DIR/$rule_id" > "$skill_file" |
306 | 308 |
|
307 | 309 | log_success "Generated $rule_id/SKILL.md" |
308 | 310 | ((skill_count++)) || true |
|
0 commit comments