Skip to content

Instantly share code, notes, and snippets.

@rmpel
Created May 30, 2025 13:25
Show Gist options
  • Save rmpel/d1e6f9a485fde839bc8d77f66fc1029f to your computer and use it in GitHub Desktop.
Save rmpel/d1e6f9a485fde839bc8d77f66fc1029f to your computer and use it in GitHub Desktop.
Patch phpStorm workspace.xml to not break on a global script, like LocalWPs auto-prepended script.
#!/usr/bin/env bash
# example usage: cd ~/Local\ Sites ; find ./*/app/.idea/workspace.xml -exec patch-workspace.sh {} \;
[ -z "$1" ] && echo "Usage: $0 filepath-to-workspace.xml" >&2 && exit 1;
xmlpath="$1"
[ ! -f "$xmlpath" ] && echo File not found: $1 && echo "Usage: $0 filepath-to-workspace.xml" >&2 && exit 2;
cp "$xmlpath" "$xmlpath.bak"
if grep -q 'PhpDebugGeneral' "$xmlpath"; then
if grep -q 'xdebug_force_break_when_no_path_mapping=' "$xmlpath"; then
sed -i '' -e 's/xdebug_force_break_when_no_path_mapping="true"/xdebug_force_break_when_no_path_mapping="false"/g' "$xmlpath"
else
sed -i '' -e 's/<component name="PhpDebugGeneral"/<component name="PhpDebugGeneral" xdebug_force_break_when_no_path_mapping="false"/g' "$xmlpath"
fi
if grep -q 'xdebug_force_break_when_outside_project=' "$xmlpath"; then
sed -i '' -e 's/xdebug_force_break_when_outside_project="true"/xdebug_force_break_when_outside_project="false"/g' "$xmlpath"
else
sed -i '' -e 's/<component name="PhpDebugGeneral"/<component name="PhpDebugGeneral" xdebug_force_break_when_outside_project="false"/g' "$xmlpath"
fi
elif grep -q 'PhpServers' "$xmlpath"; then
awk '/<component name="PhpServers">/ { print " <component name=\"PhpDebugGeneral\" listening_started=\"true\" xdebug_force_break_when_no_path_mapping=\"false\" xdebug_force_break_when_outside_project=\"false\" />"; print; next }1' "$xmlpath" > "$xmlpath.tmp"
mv "$xmlpath.tmp" "$xmlpath"
else
awk '/<project [^>]+>/ { print ; print " <component name=\"PhpDebugGeneral\" listening_started=\"true\" xdebug_force_break_when_no_path_mapping=\"false\" xdebug_force_break_when_outside_project=\"false\" />"; next }1' "$xmlpath" > "$xmlpath.tmp"
mv "$xmlpath.tmp" "$xmlpath"
fi
@rmpel
Copy link
Author

rmpel commented May 30, 2025

Yes, I know, a lot of repetition, but this works and it keeps as much as possible from the original XML content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment