Created
May 30, 2025 13:25
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, I know, a lot of repetition, but this works and it keeps as much as possible from the original XML content.