Last active
June 21, 2022 14:43
-
-
Save ssaavedra/c28e6405fbd9cc1f853bc99465773f59 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# "Repair" VSCode WSLServer script to include genie invocation | |
# Author: Santiago Saavedra <[email protected]> | |
# License: Public Domain or CC0 | |
patch_file () { | |
patch -r- -F0 "$1" <(cat <<EOF | |
--- /dev/null 2022-02-15 00:14:03.180843900 +0100 | |
+++ $1 2022-03-06 13:07:22.380000000 +0100 | |
@@ -8,2 +8,10 @@ | |
+## BEGIN GENIE PATCH | |
+# Check if inside bottle | |
+if ! genie -b; then | |
+ # Rerun current script inside bottle | |
+ exec genie -c "\$0" "\$@" | |
+fi | |
+## END GENIE PATCH | |
+ | |
shift 4 | |
EOF | |
) | |
} | |
getwinprofile () { | |
(cd /mnt/c && /mnt/c/Windows/System32/cmd.exe "/C" "echo %USERPROFILE%" 2>&1 | tr -d '\r') | |
} | |
find_extensions () { | |
USERPROFILE_WIN=$(getwinprofile) | |
USERPROFILE_FHS=$(wslpath -u "$USERPROFILE_WIN") | |
VSCODE_REMOTE_EXTENSIONS="$USERPROFILE_FHS/.vscode/extensions/ms-vscode-remote.remote-wsl-"* | |
for extension in $VSCODE_REMOTE_EXTENSIONS; do | |
if [[ -d "$extension" ]]; then | |
echo "$extension" | |
fi | |
done | |
} | |
patch_extension () { | |
local extension_dir="$1" | |
local extension_file="$extension_dir/scripts/wslServer.sh" | |
if [[ -f "$extension_file" ]]; then | |
# Check if we need to patch | |
if ! grep -q "## BEGIN GENIE PATCH" "$extension_file"; then | |
echo "Patching $extension_file" | |
patch_file "$extension_file" | |
else | |
echo "Already patched $extension_file" | |
fi | |
fi | |
} | |
for extension in $(find_extensions); do | |
patch_extension "$extension" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment