diff --git a/thefuck/output_readers/rerun.py b/thefuck/output_readers/rerun.py index b7ffe24..29461ca 100644 --- a/thefuck/output_readers/rerun.py +++ b/thefuck/output_readers/rerun.py @@ -5,6 +5,8 @@ from subprocess import Popen, PIPE, STDOUT from psutil import AccessDenied, Process, TimeoutExpired from .. import logs from ..conf import settings +from ..shells import shell +from ..shells.nushell import Nushell def _kill_process(proc): @@ -17,8 +19,11 @@ def _kill_process(proc): try: proc.kill() except AccessDenied: - logs.debug(u'Rerun: process PID {} ({}) could not be terminated'.format( - proc.pid, proc.exe())) + logs.debug( + "Rerun: process PID {} ({}) could not be terminated".format( + proc.pid, proc.exe() + ) + ) def _wait_output(popen, is_slow): @@ -33,8 +38,7 @@ def _wait_output(popen, is_slow): """ proc = Process(popen.pid) try: - proc.wait(settings.wait_slow_command if is_slow - else settings.wait_command) + proc.wait(settings.wait_slow_command if is_slow else settings.wait_command) return True except TimeoutExpired: for child in proc.children(recursive=True): @@ -55,18 +59,25 @@ def get_output(script, expanded): env.update(settings.env) if six.PY2: - expanded = expanded.encode('utf-8') + expanded = expanded.encode("utf-8") split_expand = shlex.split(expanded) is_slow = split_expand[0] in settings.slow_commands if split_expand else False - with logs.debug_time(u'Call: {}; with env: {}; is slow: {}'.format( - script, env, is_slow)): - result = Popen(expanded, shell=True, stdin=PIPE, - stdout=PIPE, stderr=STDOUT, env=env) + with logs.debug_time( + "Call: {}; with env: {}; is slow: {}".format(script, env, is_slow) + ): + if isinstance(shell, Nushell): + result = Popen( + ["nu", "-c", expanded], stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=env + ) + else: + result = Popen( + expanded, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=env + ) if _wait_output(result, is_slow): - output = result.stdout.read().decode('utf-8', errors='replace') - logs.debug(u'Received output: {}'.format(output)) + output = result.stdout.read().decode("utf-8", errors="replace") + logs.debug("Received output: {}".format(output)) return output else: - logs.debug(u'Execution timed out!') + logs.debug("Execution timed out!") return None