summaryrefslogtreecommitdiff
path: root/plugins/plugin-dev/skills/plugin-settings/scripts/parse-frontmatter.sh
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugin-dev/skills/plugin-settings/scripts/parse-frontmatter.sh')
-rwxr-xr-xplugins/plugin-dev/skills/plugin-settings/scripts/parse-frontmatter.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/plugins/plugin-dev/skills/plugin-settings/scripts/parse-frontmatter.sh b/plugins/plugin-dev/skills/plugin-settings/scripts/parse-frontmatter.sh
new file mode 100755
index 00000000..f247571b
--- /dev/null
+++ b/plugins/plugin-dev/skills/plugin-settings/scripts/parse-frontmatter.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+# Frontmatter Parser Utility
+# Extracts YAML frontmatter from .local.md files
+
+set -euo pipefail
+
+# Usage
+show_usage() {
+ echo "Usage: $0 <settings-file.md> [field-name]"
+ echo ""
+ echo "Examples:"
+ echo " # Show all frontmatter"
+ echo " $0 .claude/my-plugin.local.md"
+ echo ""
+ echo " # Extract specific field"
+ echo " $0 .claude/my-plugin.local.md enabled"
+ echo ""
+ echo " # Extract and use in script"
+ echo " ENABLED=\$($0 .claude/my-plugin.local.md enabled)"
+ exit 0
+}
+
+if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
+ show_usage
+fi
+
+FILE="$1"
+FIELD="${2:-}"
+
+# Validate file
+if [ ! -f "$FILE" ]; then
+ echo "Error: File not found: $FILE" >&2
+ exit 1
+fi
+
+# Extract frontmatter
+FRONTMATTER=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$FILE")
+
+if [ -z "$FRONTMATTER" ]; then
+ echo "Error: No frontmatter found in $FILE" >&2
+ exit 1
+fi
+
+# If no field specified, output all frontmatter
+if [ -z "$FIELD" ]; then
+ echo "$FRONTMATTER"
+ exit 0
+fi
+
+# Extract specific field
+VALUE=$(echo "$FRONTMATTER" | grep "^${FIELD}:" | sed "s/${FIELD}: *//" | sed 's/^"\(.*\)"$/\1/' | sed "s/^'\\(.*\\)'$/\\1/")
+
+if [ -z "$VALUE" ]; then
+ echo "Error: Field '$FIELD' not found in frontmatter" >&2
+ exit 1
+fi
+
+echo "$VALUE"
+exit 0