summaryrefslogtreecommitdiff
path: root/docs/windows/polyglot-hooks.md
diff options
context:
space:
mode:
authorDrew Ritter <drew@primeradiant.com>2026-11-26 00:46:47 -0800
committerDrew Ritter <drew@primeradiant.com>2026-11-26 00:46:47 -0800
commit270c94ec16738f1dbb1e43513b09733d9600ac84 (patch)
tree0f9fc14d555fccdeb95b41906f816ecf63636e50 /docs/windows/polyglot-hooks.md
parentb96b91a34c2e8c41f2a85207763582807f1e4134 (diff)
parentf27e901302c8294370ac77bfba148c7d72bc8b78 (diff)
Merge branch 'fix/wave1-run-hook-heredoc' into fix/wave1-harness-adaptersfix/wave1-harness-adapters
Diffstat (limited to 'docs/windows/polyglot-hooks.md')
-rw-r--r--docs/windows/polyglot-hooks.md14
1 files changed, 12 insertions, 2 deletions
diff --git a/docs/windows/polyglot-hooks.md b/docs/windows/polyglot-hooks.md
index 0379037..d6970e1 100644
--- a/docs/windows/polyglot-hooks.md
+++ b/docs/windows/polyglot-hooks.md
@@ -176,7 +176,12 @@ Your hook logic goes in the extensionless script file. A few portable patterns:
nl='
'
tab=' '
-cr=$(printf '\r')
+if [ -n "${BASH_VERSION:-}" ]; then
+ # shellcheck disable=SC3045 # bash builtin avoids a subshell fork (#2081)
+ printf -v cr '\r'
+else
+ cr=$(printf '\r' 2>/dev/null || true)
+fi
replace_all() {
rest=$1
@@ -202,8 +207,13 @@ escape_for_json() {
[ -z "$cr" ] || replace_all "$escaped" "$cr" '\r'
replace_all "$escaped" "$nl" '\n'
replace_all "$escaped" "$tab" '\t'
- printf '%s' "$escaped"
+ using_superpowers_escaped=$escaped
}
+
+# The result is left in a variable instead of printed, because capturing
+# output with $(...) forks. Call the function, then read the variable:
+# escape_for_json "$content"
+# json=$using_superpowers_escaped
```
## Troubleshooting