ssh kitten: Dont transfer terminfo if any of the -Nnf arguments are passed to ssh
This commit is contained in:
parent
b752d1ca48
commit
cd80a85d2d
@ -2,6 +2,7 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -42,14 +43,18 @@ exec -a "-$shell_name" "$0"
|
|||||||
def parse_ssh_args(args):
|
def parse_ssh_args(args):
|
||||||
boolean_ssh_args = {'-' + x for x in '46AaCfGgKkMNnqsTtVvXxYy'}
|
boolean_ssh_args = {'-' + x for x in '46AaCfGgKkMNnqsTtVvXxYy'}
|
||||||
other_ssh_args = {'-' + x for x in 'bBcDeEFIJlLmOopQRSWw'}
|
other_ssh_args = {'-' + x for x in 'bBcDeEFIJlLmOopQRSWw'}
|
||||||
|
passthrough_args = {'-' + x for x in 'Nnf'}
|
||||||
ssh_args = []
|
ssh_args = []
|
||||||
server_args = []
|
server_args = []
|
||||||
expecting_option_val = False
|
expecting_option_val = False
|
||||||
|
passthrough = False
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if server_args:
|
if server_args:
|
||||||
server_args.append(arg)
|
server_args.append(arg)
|
||||||
continue
|
continue
|
||||||
if arg.startswith('-'):
|
if arg.startswith('-'):
|
||||||
|
if arg in passthrough_args:
|
||||||
|
passthrough = True
|
||||||
if arg in boolean_ssh_args:
|
if arg in boolean_ssh_args:
|
||||||
ssh_args.append(arg)
|
ssh_args.append(arg)
|
||||||
continue
|
continue
|
||||||
@ -65,22 +70,24 @@ def parse_ssh_args(args):
|
|||||||
server_args.append(arg)
|
server_args.append(arg)
|
||||||
if not server_args:
|
if not server_args:
|
||||||
raise SystemExit('Must specify server to connect to')
|
raise SystemExit('Must specify server to connect to')
|
||||||
return ssh_args, server_args
|
return ssh_args, server_args, passthrough
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
ssh_args, server_args = parse_ssh_args(args[1:])
|
ssh_args, server_args, passthrough = parse_ssh_args(args[1:])
|
||||||
terminfo = subprocess.check_output(['infocmp']).decode('utf-8')
|
if passthrough:
|
||||||
sh_script = SHELL_SCRIPT.replace('TERMINFO', terminfo, 1)
|
cmd = ['ssh'] + ssh_args + server_args
|
||||||
if len(server_args) > 1:
|
|
||||||
command_to_execute = ["'{}'".format(c.replace("'", """'"'"'""")) for c in server_args[1:]]
|
|
||||||
command_to_execute = 'cmd=({}); exec "$cmd"'.format(' '.join(command_to_execute))
|
|
||||||
else:
|
else:
|
||||||
command_to_execute = ''
|
terminfo = subprocess.check_output(['infocmp']).decode('utf-8')
|
||||||
sh_script = sh_script.replace('EXEC_CMD', command_to_execute)
|
sh_script = SHELL_SCRIPT.replace('TERMINFO', terminfo, 1)
|
||||||
cmd = ['ssh'] + ssh_args + ['-t', server_args[0], sh_script] + server_args[1:]
|
if len(server_args) > 1:
|
||||||
p = subprocess.Popen(cmd)
|
command_to_execute = ["'{}'".format(c.replace("'", """'"'"'""")) for c in server_args[1:]]
|
||||||
raise SystemExit(p.wait())
|
command_to_execute = 'cmd=({}); exec "$cmd"'.format(' '.join(command_to_execute))
|
||||||
|
else:
|
||||||
|
command_to_execute = ''
|
||||||
|
sh_script = sh_script.replace('EXEC_CMD', command_to_execute)
|
||||||
|
cmd = ['ssh'] + ssh_args + ['-t', server_args[0], sh_script] + server_args[1:]
|
||||||
|
os.execvp('ssh', cmd)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user