1
0
Fork 0

Fix running commands with directories; also fix editing

master
LEdoian 5 years ago
parent 7c02d2c1da
commit f6497245b9

@ -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,6 +146,8 @@ 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)
@ -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

Loading…
Cancel
Save