File size: 2,712 Bytes
7f0ec95 | 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 | #!/bin/bash
# Settings File Validator
# Validates .claude/plugin-name.local.md structure
set -euo pipefail
# Usage
if [ $# -eq 0 ]; then
echo "Usage: $0 <path/to/settings.local.md>"
echo ""
echo "Validates plugin settings file for:"
echo " - File existence and readability"
echo " - YAML frontmatter structure"
echo " - Required --- markers"
echo " - Field format"
echo ""
echo "Example: $0 .claude/my-plugin.local.md"
exit 1
fi
SETTINGS_FILE="$1"
echo "π Validating settings file: $SETTINGS_FILE"
echo ""
# Check 1: File exists
if [ ! -f "$SETTINGS_FILE" ]; then
echo "β File not found: $SETTINGS_FILE"
exit 1
fi
echo "β
File exists"
# Check 2: File is readable
if [ ! -r "$SETTINGS_FILE" ]; then
echo "β File is not readable"
exit 1
fi
echo "β
File is readable"
# Check 3: Has frontmatter markers
MARKER_COUNT=$(grep -c '^---$' "$SETTINGS_FILE" 2>/dev/null || echo "0")
if [ "$MARKER_COUNT" -lt 2 ]; then
echo "β Invalid frontmatter: found $MARKER_COUNT '---' markers (need at least 2)"
echo " Expected format:"
echo " ---"
echo " field: value"
echo " ---"
echo " Content..."
exit 1
fi
echo "β
Frontmatter markers present"
# Check 4: Extract and validate frontmatter
FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$SETTINGS_FILE")
if [ -z "$FRONTMATTER" ]; then
echo "β Empty frontmatter (nothing between --- markers)"
exit 1
fi
echo "β
Frontmatter not empty"
# Check 5: Frontmatter has valid YAML-like structure
if ! echo "$FRONTMATTER" | grep -q ':'; then
echo "β οΈ Warning: Frontmatter has no key:value pairs"
fi
# Check 6: Look for common fields
echo ""
echo "Detected fields:"
echo "$FRONTMATTER" | grep '^[a-z_][a-z0-9_]*:' | while IFS=':' read -r key value; do
echo " - $key: ${value:0:50}"
done
# Check 7: Validate common boolean fields
for field in enabled strict_mode; do
VALUE=$(echo "$FRONTMATTER" | grep "^${field}:" | sed "s/${field}: *//" || true)
if [ -n "$VALUE" ]; then
if [ "$VALUE" != "true" ] && [ "$VALUE" != "false" ]; then
echo "β οΈ Field '$field' should be boolean (true/false), got: $VALUE"
fi
fi
done
# Check 8: Check body exists
BODY=$(awk '/^---$/{i++; next} i>=2' "$SETTINGS_FILE")
echo ""
if [ -n "$BODY" ]; then
BODY_LINES=$(echo "$BODY" | wc -l | tr -d ' ')
echo "β
Markdown body present ($BODY_LINES lines)"
else
echo "β οΈ No markdown body (frontmatter only)"
fi
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββ"
echo "β
Settings file structure is valid"
echo ""
echo "Reminder: Changes to this file require restarting Claude Code"
exit 0
|