From 285d57eb01c6ce698d87f5fbd10bc498bb84d380 Mon Sep 17 00:00:00 2001 From: mcarton Date: Tue, 11 Aug 2015 10:49:19 +0200 Subject: [PATCH] #331 Fix bug with empty commands --- tests/test_main.py | 2 ++ thefuck/main.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index 4d66e7ee..0ea2cc2e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -35,6 +35,8 @@ class TestGetCommand(object): env={}) @pytest.mark.parametrize('args, result', [ + (['thefuck', ''], None), + (['thefuck', '', ''], None), (['thefuck', 'ls', '-la'], 'ls -la'), (['thefuck', 'ls'], 'ls')]) def test_get_command_script(self, args, result): diff --git a/thefuck/main.py b/thefuck/main.py index 53e3aa92..c30ff7cf 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -27,7 +27,7 @@ def setup_user_dir(): def wait_output(settings, popen): """Returns `True` if we can get output of the command in the - `wait_command` time. + `settings.wait_command` time. Command will be killed if it wasn't finished in the time. @@ -50,6 +50,7 @@ def get_command(settings, args): else: script = ' '.join(args[1:]) + script = script.strip() if not script: return @@ -91,6 +92,11 @@ def fix_command(): logs.debug(u'Run with settings: {}'.format(pformat(settings)), settings) command = get_command(settings, sys.argv) + + if not command: + logs.debug('Empty command, nothing to do', settings) + return + corrected_commands = get_corrected_commands(command, user_dir, settings) selected_command = select_command(corrected_commands, settings) if selected_command: