-
-
Save pandada8/24c6195000252782e69e6ca85a88d749 to your computer and use it in GitHub Desktop.
Launch code from ssh
This file contains 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/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