|
@@ -17,23 +17,17 @@ fi
|
|
|
# Read using-superpowers content
|
|
# Read using-superpowers content
|
|
|
using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill")
|
|
using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill")
|
|
|
|
|
|
|
|
-# Escape outputs for JSON using pure bash
|
|
|
|
|
|
|
+# Escape string for JSON embedding using bash parameter substitution.
|
|
|
|
|
+# Each ${s//old/new} is a single C-level pass - orders of magnitude
|
|
|
|
|
+# faster than the character-by-character loop this replaces.
|
|
|
escape_for_json() {
|
|
escape_for_json() {
|
|
|
- local input="$1"
|
|
|
|
|
- local output=""
|
|
|
|
|
- local i char
|
|
|
|
|
- for (( i=0; i<${#input}; i++ )); do
|
|
|
|
|
- char="${input:$i:1}"
|
|
|
|
|
- case "$char" in
|
|
|
|
|
- $'\\') output+='\\' ;;
|
|
|
|
|
- '"') output+='\"' ;;
|
|
|
|
|
- $'\n') output+='\n' ;;
|
|
|
|
|
- $'\r') output+='\r' ;;
|
|
|
|
|
- $'\t') output+='\t' ;;
|
|
|
|
|
- *) output+="$char" ;;
|
|
|
|
|
- esac
|
|
|
|
|
- done
|
|
|
|
|
- printf '%s' "$output"
|
|
|
|
|
|
|
+ local s="$1"
|
|
|
|
|
+ s="${s//\\/\\\\}"
|
|
|
|
|
+ s="${s//\"/\\\"}"
|
|
|
|
|
+ s="${s//$'\n'/\\n}"
|
|
|
|
|
+ s="${s//$'\r'/\\r}"
|
|
|
|
|
+ s="${s//$'\t'/\\t}"
|
|
|
|
|
+ printf '%s' "$s"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
using_superpowers_escaped=$(escape_for_json "$using_superpowers_content")
|
|
using_superpowers_escaped=$(escape_for_json "$using_superpowers_content")
|