diff --git a/kittens/ssh/main.py b/kittens/ssh/main.py index c1db91f24..1e7948b4f 100644 --- a/kittens/ssh/main.py +++ b/kittens/ssh/main.py @@ -219,7 +219,8 @@ def prepare_exec_cmd(remote_args: Sequence[str], is_python: bool) -> str: def bootstrap_script( script_type: str = 'sh', remote_args: Sequence[str] = (), ssh_opts_dict: Dict[str, Dict[str, Any]] = {}, - test_script: str = '', request_id: Optional[str] = None, cli_hostname: str = '', cli_uname: str = '' + test_script: str = '', request_id: Optional[str] = None, cli_hostname: str = '', cli_uname: str = '', + request_data: str = '1', ) -> Tuple[str, Dict[str, str], SharedMemory]: if request_id is None: request_id = os.environ['KITTY_PID'] + '-' + os.environ['KITTY_WINDOW_ID'] @@ -235,7 +236,7 @@ def bootstrap_script( atexit.register(shm.unlink) replacements = { 'DATA_PASSWORD': pw, 'PASSWORD_FILENAME': shm.name, 'EXEC_CMD': exec_cmd, 'TEST_SCRIPT': test_script, - 'REQUEST_ID': request_id + 'REQUEST_ID': request_id, 'REQUEST_DATA': request_data, } return prepare_script(ans, replacements), replacements, shm diff --git a/shell-integration/ssh/bootstrap.py b/shell-integration/ssh/bootstrap.py index c99c41cbc..b7a58c409 100644 --- a/shell-integration/ssh/bootstrap.py +++ b/shell-integration/ssh/bootstrap.py @@ -21,6 +21,7 @@ import tty tty_fd = -1 original_termios_state = None data_dir = shell_integration_dir = '' +request_data = int('REQUEST_DATA') leading_data = b'' HOME = os.path.expanduser('~') login_shell = pwd.getpwuid(os.geteuid()).pw_shell or 'sh' @@ -217,23 +218,25 @@ def main(): except OSError: pass else: - try: - original_termios_state = termios.tcgetattr(tty_fd) - except OSError: - pass - else: - tty.setraw(tty_fd, termios.TCSANOW) - new_state = termios.tcgetattr(tty_fd) - new_state[3] &= ~termios.ECHO - new_state[-1][termios.VMIN] = 1 - new_state[-1][termios.VTIME] = 0 - termios.tcsetattr(tty_fd, termios.TCSANOW, new_state) - if original_termios_state is not None: - try: + if request_data: + try: + original_termios_state = termios.tcgetattr(tty_fd) + except OSError: + pass + else: + tty.setraw(tty_fd, termios.TCSANOW) + new_state = termios.tcgetattr(tty_fd) + new_state[3] &= ~termios.ECHO + new_state[-1][termios.VMIN] = 1 + new_state[-1][termios.VTIME] = 0 + termios.tcsetattr(tty_fd, termios.TCSANOW, new_state) + try: + if original_termios_state is not None: send_data_request() + if tty_fd > -1: get_data() - finally: - cleanup() + finally: + cleanup() cwd = os.environ.pop('KITTY_LOGIN_CWD', '') if cwd: os.chdir(cwd) diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index cdcc0aac4..031d76005 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -5,6 +5,8 @@ saved_tty_settings="" tdir="" shell_integration_dir="" +compression="gz" + cleanup_on_bootstrap_exit() { [ -n "$saved_tty_settings" ] && command stty "$saved_tty_settings" 2> /dev/null < /dev/tty [ -n "$tdir" ] && command rm -rf "$tdir" @@ -177,9 +179,10 @@ hostname="$HOSTNAME" leading_data="" login_cwd="" -init_tty && trap "cleanup_on_bootstrap_exit" EXIT -if [ "$tty_ok" = "y" ]; then - compression="gz" +request_data="REQUEST_DATA" +[ "$request_data" = "1" ] && init_tty +trap "cleanup_on_bootstrap_exit" EXIT +if [ "$tty_ok" = "y" -a "$request_data" = "1" ]; then command -v "bzip2" > /dev/null 2> /dev/null && compression="bz2" dcs_to_kitty "ssh" "id="REQUEST_ID":hostname="$hostname":pwfile="PASSWORD_FILENAME":user="$USER":compression="$compression":pw="DATA_PASSWORD"" fi