Skip to content

Instantly share code, notes, and snippets.

@NoahBres
Created June 7, 2024 08:35
Show Gist options
  • Save NoahBres/3c4ab0346b2cd484b059e786c8827cf6 to your computer and use it in GitHub Desktop.
Save NoahBres/3c4ab0346b2cd484b059e786c8827cf6 to your computer and use it in GitHub Desktop.
#! /usr/bin/env zsh
# Find the latest spawned VSCode server. Link to its node process
local node_process=$(echo ~/.vscode-server/cli/servers/*/server/node(*oc[1]N))
if [[ -z ${node_process} ]]
then
echo "VSCode remote server process not found"
exit 1
fi
# ps ux to find the processes, pipe it into grep to search for the $node_process name and the line that contains "start-server"
local our_process=$(ps ux | grep $node_process | grep "start-server")
if [[ -z ${our_process} ]]
then
echo "Running VSCode server not found"
exit 1
fi
# find second column of our process
local our_pid=$(echo $our_process | awk '{print $2}')
if [[ -z ${our_pid} ]]
then
echo "VSCode IPC socket not found"
exit 1
fi
local our_socket=$(ss -lx -p -s | grep "pid=$our_pid" | grep "\.sock")
if [[ -z ${our_socket} ]]
then
echo "VSCode IPC socket not found"
exit 1
fi
# find 4th column of our_socket
local socket_path=$(echo $our_socket | awk '{print $5}')
if [[ -z ${socket_path} ]]
then
echo "VSCode IPC socket packet not found"
exit 1
fi
# trim the "/node" string at the end of $node_process
base_process=${node_process%"/node"}
VSCODE_IPC_HOOK_CLI=$socket_path $(echo "${base_process}/bin/remote-cli/code") $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment