mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
Show user's $EDITOR in output
It looks nicer with confirmation and also checks the user actually has an $EDITOR.
This commit is contained in:
parent
e4b97af73e
commit
de513cacb1
@ -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]))
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user