22
33# based on https://stackoverflow.com/a/60949722
44
5- from pathlib import Path
6- import subprocess as sp
7- from typing import Iterable , List , Tuple
85import time
6+ import subprocess as sp
97import os
8+ from distutils .spawn import find_executable
9+ from typing import Iterable , List , Tuple
10+ from pathlib import Path
1011
1112MAX_IDLE_TIME = 4 * 60 * 60
1213
@@ -38,7 +39,15 @@ def next_open_socket(socks: Iterable[Path]) -> Path:
3839 'Please make sure to connect to this machine with a standard VS Code remote SSH session before using this tool.'
3940 )
4041
42+ def check_for_binaries ():
43+ if find_executable ('socat' ) is None :
44+ fail (
45+ '"socat" not found in $PATH, but is required for code-connect'
46+ )
47+
4148def main (shell : str = None , max_idle_time : int = MAX_IDLE_TIME ):
49+ check_for_binaries ()
50+
4251 # Determine shell for outputting the proper format
4352 if not shell :
4453 shell = os .getenv ('SHELL' , 'bash' )
@@ -62,9 +71,10 @@ def main(shell: str = None, max_idle_time: int = MAX_IDLE_TIME):
6271
6372 code_binary = code_repo / 'bin' / 'code'
6473
65- # List all possible sockets
74+ # List all possible sockets for the current user
6675 # Some of these are obsolete and not listening
67- socks = sort_by_access_timestamp (Path ('/run/user/1000/' ).glob ('vscode-ipc-*.sock' ))
76+ uid = os .getuid ()
77+ socks = sort_by_access_timestamp (Path (f'/run/user/{ uid } /' ).glob ('vscode-ipc-*.sock' ))
6878
6979 # Only consider the ones that were active N seconds ago
7080 now = time .time ()
0 commit comments