Skip to content

Instantly share code, notes, and snippets.

@GongT
Created September 9, 2024 07:55
Show Gist options
  • Save GongT/01e1db2e062419173e72862100d50217 to your computer and use it in GitHub Desktop.
Save GongT/01e1db2e062419173e72862100d50217 to your computer and use it in GitHub Desktop.
expose VSCode remote socket to all user
#!/usr/bin/bash
SHOULD_CONNECT=
for SOCKET_FILE in "/run/user/$UID/vscode-ipc-"*.sock; do
if socat -u OPEN:/dev/null "UNIX-CONNECT:$SOCKET_FILE" &>/dev/null; then
echo "may connect? $SOCKET_FILE" >&2
SHOULD_CONNECT=$SOCKET_FILE
else
echo "delete ununsed socket: $SOCKET_FILE" >&2
unlink "$SOCKET_FILE"
fi
done
if [[ $SHOULD_CONNECT ]]; then
exec /usr/lib/systemd/systemd-socket-proxyd --exit-idle-time=10s "$SHOULD_CONNECT"
else
echo "no socket exists" >&2
exit 233
fi
[Unit]
Description=expose VSCode remote to all user
Requires=vscode-remote.socket
After=vscode-remote.socket
[Service]
Type=notify
WorkingDirectory=%Y
ExecStart=/usr/bin/bash start-proxy.sh
NotifyAccess=all
RestartPreventExitStatus=233
Restart=no
[Unit]
Description=expose VSCode remote to all user
[Install]
WantedBy=sockets.target
[Socket]
ListenStream=/tmp/vscode-remote.socket
Service=vscode-remote.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment