Use robust string matching and printf for user-mutable refs

- Replace grep -qw with bash substring match for filename detection
- Replace echo with printf '%s\n' to prevent content mangling
This commit is contained in:
gnekt
2026-03-24 12:29:26 +01:00
parent a0edee3fa4
commit 8eb103d454
2 changed files with 3 additions and 3 deletions

View File

@@ -129,7 +129,7 @@ for ref in "$REPO_DIR/references/"*.md; do
ref_name="$(basename "$ref")"
# On reinstall, preserve user-mutable reference files
if [[ $EXISTING -eq 1 && -f "$VAULT_DIR/.claude/references/$ref_name" ]]; then
if echo "$USER_MUTABLE_REFS" | grep -qw "$ref_name"; then
if [[ " $USER_MUTABLE_REFS " == *" $ref_name "* ]]; then
warn "Preserving existing $ref_name (run updateme.sh to merge upstream changes)"
echo "$ref_name" >> "$VAULT_DIR/.claude/references/.core-manifest"
continue

View File

@@ -159,7 +159,7 @@ for ref in "$REPO_DIR/references/"*.md; do
vault_copy="$VAULT_DIR/.claude/references/$name"
# For user-mutable files: preserve custom agent content
if echo "$USER_MUTABLE_REFS" | grep -qw "$name" && [[ -f "$vault_copy" ]]; then
if [[ " $USER_MUTABLE_REFS " == *" $name "* ]] && [[ -f "$vault_copy" ]]; then
# Extract user's custom section (from "## Custom Agents" to end of file)
custom_section=""
if grep -qn "^## Custom Agents" "$vault_copy"; then
@@ -200,7 +200,7 @@ for ref in "$REPO_DIR/references/"*.md; do
repo_custom_line=$(grep -n "^## Custom Agents" "$vault_copy" | head -1 | cut -d: -f1)
if [[ -n "$repo_custom_line" ]]; then
head -n "$((repo_custom_line - 1))" "$vault_copy" > "$vault_copy.tmp"
echo "$custom_section" >> "$vault_copy.tmp"
printf '%s\n' "$custom_section" >> "$vault_copy.tmp"
mv "$vault_copy.tmp" "$vault_copy"
fi
fi