|
|
|
@ -128,7 +128,7 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
|
|
|
|
|
with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
|
|
|
|
|
# Fill the file with data
|
|
|
|
|
for cmd in hunk:
|
|
|
|
|
tmpfile.file.write(f"{cmd.user}\t{cmd.directory}\t{cmd.command}\n")
|
|
|
|
|
tmpfile.file.write(f"{cmd.user}\t{cmd.directory if cmd.directory else ''}\t{cmd.command}\n")
|
|
|
|
|
tmpfile.file.flush() # Should not be needed, but better safe than sorry
|
|
|
|
|
# Let the user edit the file
|
|
|
|
|
import os
|
|
|
|
@ -146,9 +146,11 @@ def user_action(hunk: Sequence[Command], context=None) -> Sequence[Command]:
|
|
|
|
|
if line == '':
|
|
|
|
|
continue
|
|
|
|
|
parts = line.split('\t', maxsplit=2)
|
|
|
|
|
# Change directory to None if it is not specified
|
|
|
|
|
parts[1] = parts[1].strip() if parts[1].strip() != '' else None
|
|
|
|
|
new_hunk.append(Command(user=parts[0],directory=parts[1],command=parts[2],context=None))
|
|
|
|
|
# Python has no goto for restarting, but we can recurse
|
|
|
|
|
return user_action(new_hunk, context)
|
|
|
|
|
# Python has no goto for restarting, but we can recurse
|
|
|
|
|
return user_action(new_hunk, context)
|
|
|
|
|
elif answer.startswith(('y', 'Y')):
|
|
|
|
|
return hunk
|
|
|
|
|
elif answer.startswith(('n', 'N')):
|
|
|
|
@ -160,11 +162,12 @@ def run_command(cmd: Command):
|
|
|
|
|
# Generate and run the SSH command.
|
|
|
|
|
global host
|
|
|
|
|
local_command = ['ssh', host]
|
|
|
|
|
remote_command = cmd.command
|
|
|
|
|
if cmd.user is not None:
|
|
|
|
|
local_command.extend(['-l', cmd.user])
|
|
|
|
|
if cmd.directory is not None:
|
|
|
|
|
cmd.command += f'cd {cmd.directory}; {cmd.command}'
|
|
|
|
|
local_command.append(cmd.command)
|
|
|
|
|
remote_command = f'cd {cmd.directory}; {remote_command}'
|
|
|
|
|
local_command.append(remote_command)
|
|
|
|
|
|
|
|
|
|
# Run
|
|
|
|
|
import subprocess
|
|
|
|
|