From de513cacb150049e3f95434f8d6d30b7ed1e0ea7 Mon Sep 17 00:00:00 2001 From: mcarton Date: Wed, 29 Jul 2015 18:35:59 +0200 Subject: [PATCH] Show user's $EDITOR in output It looks nicer with confirmation and also checks the user actually has an $EDITOR. --- tests/rules/test_fix_file.py | 15 +++++++++++++-- thefuck/rules/fix_file.py | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/rules/test_fix_file.py b/tests/rules/test_fix_file.py index c9411b42..2eb42cab 100644 --- a/tests/rules/test_fix_file.py +++ b/tests/rules/test_fix_file.py @@ -1,4 +1,5 @@ import pytest +import os from thefuck.rules.fix_file import match, get_new_command from tests.utils import Command @@ -157,11 +158,21 @@ ReferenceError: conole is not defined @pytest.mark.parametrize('test', tests) -def test_match(test): +def test_match(monkeypatch, test): + monkeypatch.setenv('EDITOR', 'dummy_editor') assert match(Command(stderr=test[4]), None) +@pytest.mark.parametrize('test', tests) +def test_not_match(monkeypatch, test): + if 'EDITOR' in os.environ: + monkeypatch.delenv('EDITOR') + + assert not match(Command(stderr=test[4]), None) + + @pytest.mark.parametrize('test', tests) def test_get_new_command(monkeypatch, test): + monkeypatch.setenv('EDITOR', 'dummy_editor') assert (get_new_command(Command(script=test[0], stderr=test[4]), None) == - '$EDITOR {} +{} && {}'.format(test[1], test[2], test[0])) + 'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0])) diff --git a/thefuck/rules/fix_file.py b/thefuck/rules/fix_file.py index 4b7626bc..5f4aafb9 100644 --- a/thefuck/rules/fix_file.py +++ b/thefuck/rules/fix_file.py @@ -1,4 +1,5 @@ import re +import os from thefuck.utils import memoize from thefuck import shells @@ -49,7 +50,7 @@ def _search(stderr): def match(command, settings): - return _search(command.stderr) + return 'EDITOR' in os.environ and _search(command.stderr) def get_new_command(command, settings): @@ -57,5 +58,5 @@ def get_new_command(command, settings): # Note: there does not seem to be a standard for columns, so they are just # ignored for now - return shells.and_('$EDITOR {} +{}'.format(m.group('file'), m.group('line')), + return shells.and_('{} {} +{}'.format(os.environ['EDITOR'], m.group('file'), m.group('line')), command.script)