spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / plugins / plugin-dev / skills / plugin-settings / scripts / parse-frontmatter.sh
59 lines · 1.2 KBRaw
1#!/bin/bash
2# Frontmatter Parser Utility
3# Extracts YAML frontmatter from .local.md files
4
5set -euo pipefail
6
7# Usage
8show_usage() {
9 echo "Usage: $0 <settings-file.md> [field-name]"
10 echo ""
11 echo "Examples:"
12 echo " # Show all frontmatter"
13 echo " $0 .claude/my-plugin.local.md"
14 echo ""
15 echo " # Extract specific field"
16 echo " $0 .claude/my-plugin.local.md enabled"
17 echo ""
18 echo " # Extract and use in script"
19 echo " ENABLED=\$($0 .claude/my-plugin.local.md enabled)"
20 exit 0
21}
22
23if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
24 show_usage
25fi
26
27FILE="$1"
28FIELD="${2:-}"
29
30# Validate file
31if [ ! -f "$FILE" ]; then
32 echo "Error: File not found: $FILE" >&2
33 exit 1
34fi
35
36# Extract frontmatter
37FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$FILE")
38
39if [ -z "$FRONTMATTER" ]; then
40 echo "Error: No frontmatter found in $FILE" >&2
41 exit 1
42fi
43
44# If no field specified, output all frontmatter
45if [ -z "$FIELD" ]; then
46 echo "$FRONTMATTER"
47 exit 0
48fi
49
50# Extract specific field
51VALUE=$(echo "$FRONTMATTER" | grep "^${FIELD}:" | sed "s/${FIELD}: *//" | sed 's/^"\(.*\)"$/\1/' | sed "s/^'\\(.*\\)'$/\\1/")
52
53if [ -z "$VALUE" ]; then
54 echo "Error: Field '$FIELD' not found in frontmatter" >&2
55 exit 1
56fi
57
58echo "$VALUE"
59exit 0