Skip to content

Instantly share code, notes, and snippets.

@pandada8
Created April 15, 2022 08:54
Show Gist options
  • Save pandada8/24c6195000252782e69e6ca85a88d749 to your computer and use it in GitHub Desktop.
Save pandada8/24c6195000252782e69e6ca85a88d749 to your computer and use it in GitHub Desktop.
Launch code from ssh
#!/bin/env python3
from proc.tree import get_process_tree
import os
from pathlib import Path
import sys
import subprocess
ssh_connection = os.getenv('SSH_CONNECTION')
client_ip = ssh_connection.split(" ")[0]
init = get_process_tree()
for i in init.find_all(recursive=True, exe_name="node"):
if len(i.command_line) >= 2 and 'out/server-main.js' in i.command_line[1]:
if i.environ['SSH_CONNECTION'].split(' ')[0] == client_ip:
foundEnviron = None
for child in i.find_all(recursive=True):
if 'VSCODE_IPC_HOOK_CLI' in child.environ:
foundEnviron = child.environ
break
# print(i.exe_name, i.command_line)
codePath = Path(i.exe_path).parent / "bin" / "remote-cli" / "code"
cmd = [str(codePath)] + sys.argv[1:]
subprocess.call(cmd, env=foundEnviron)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment