U 优化批量执行对sh的兼容性

pull/586/head
vapao 2022-09-14 15:26:33 +08:00
parent f09dd6eb4e
commit a9b364638d
1 changed files with 4 additions and 3 deletions

View File

@ -180,7 +180,8 @@ class SSH:
counter = 0 counter = 0
self.channel = self.client.invoke_shell(**self.term) self.channel = self.client.invoke_shell(**self.term)
command = 'set +o zle\n[ -n "$BASH_VERSION" ] && set +o history\n[ -n "$ZSH_VERSION" ] && set -o no_nomatch\n' command = '[ -n "$BASH_VERSION" ] && set +o history\n'
command += '[ -n "$ZSH_VERSION" ] && set +o zle && set -o no_nomatch\n'
command += 'export PS1= && stty -echo\n' command += 'export PS1= && stty -echo\n'
command = self._handle_command(command, self.default_env) command = self._handle_command(command, self.default_env)
self.channel.sendall(command) self.channel.sendall(command)
@ -221,7 +222,7 @@ class SSH:
def _handle_command(self, command, environment): def _handle_command(self, command, environment):
new_command = commands = '' new_command = commands = ''
if not self.exec_file: if not self.exec_file:
self.exec_file = f'/tmp/{uuid4().hex}' self.exec_file = f'/tmp/spug.{uuid4().hex}'
commands += f'trap \'rm -f {self.exec_file}\' EXIT\n' commands += f'trap \'rm -f {self.exec_file}\' EXIT\n'
env_command = self._make_env_command(environment) env_command = self._make_env_command(environment)
@ -230,7 +231,7 @@ class SSH:
new_command += command new_command += command
new_command += f'\necho {self.eof} $?\n' new_command += f'\necho {self.eof} $?\n'
self.put_file_by_fl(StringIO(new_command), self.exec_file) self.put_file_by_fl(StringIO(new_command), self.exec_file)
commands += f'source {self.exec_file}\n' commands += f'. {self.exec_file}\n'
return commands return commands
def _decode(self, content): def _decode(self, content):