Skip to content

Instantly share code, notes, and snippets.

@cpuguy83
Last active August 4, 2023 20:49
Show Gist options
  • Save cpuguy83/99341bffc25d2f51c31070a2c75e97fb to your computer and use it in GitHub Desktop.
Save cpuguy83/99341bffc25d2f51c31070a2c75e97fb to your computer and use it in GitHub Desktop.
Script to connect back to a vscode-server and open the specified path
#! /usr/bin/env bash
script="$(find ~/.vscode-server/bin -iname code | tail -n 1)"
if [ -z "${script}" ]; then
echo "VSCode remote script not found"
exit 1
fi
sockets="$(find /run/user/${UID}/ -iname vscode-ipc-* 2>/dev/null)"
for s in $sockets; do
out="$(socat /dev/null "UNIX-CONNECT:${s}" 2>&1)"
if [ $? -eq 0 ]; then
socket="${s}"
break
fi
if [[ "${out}" = *"Connection refused"* ]]; then
rm "${s}"
fi
done
if [ -z "${socket}" ]; then
echo "VSCode IPC socket not found"
exit 1
fi
export VSCODE_IPC_HOOK_CLI=${socket}
if [ ! -v 1 ]; then
${script} .
else
${script} $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment