diff --git a/tests/test_main.py b/tests/test_main.py index 8288d543..10294c3c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -77,23 +77,23 @@ class TestGetCommand(object): monkeypatch.setattr('thefuck.shells.to_shell', lambda x: x) def test_get_command_calls(self, Popen): - assert main.get_command(Mock(), + assert main.get_command(Mock(env={}), ['thefuck', 'apt-get', 'search', 'vim']) \ == Command('apt-get search vim', 'stdout', 'stderr') Popen.assert_called_once_with('apt-get search vim', shell=True, stdout=PIPE, stderr=PIPE, - env={'LANG': 'C', 'GIT_TRACE': 1}) + env={}) @pytest.mark.parametrize('args, result', [ (['thefuck', 'ls', '-la'], 'ls -la'), (['thefuck', 'ls'], 'ls')]) def test_get_command_script(self, args, result): if result: - assert main.get_command(Mock(), args).script == result + assert main.get_command(Mock(env={}), args).script == result else: - assert main.get_command(Mock(), args) is None + assert main.get_command(Mock(env={}), args) is None class TestGetMatchedRule(object): diff --git a/thefuck/conf.py b/thefuck/conf.py index 14d33206..a1af962f 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -30,7 +30,8 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES, 'require_confirmation': False, 'no_colors': False, 'debug': False, - 'priority': {}} + 'priority': {}, + 'env': {'LANG': 'C', 'GIT_TRACE': '1'}} ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', 'THEFUCK_WAIT_COMMAND': 'wait_command', diff --git a/thefuck/main.py b/thefuck/main.py index e58550df..b1e0f64d 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -81,8 +81,12 @@ def get_command(settings, args): script = shells.from_shell(script) logs.debug('Call: {}'.format(script), settings) - result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, - env=dict(os.environ, LANG='C', GIT_TRACE=1)) + + env = dict(os.environ) + env.update(settings.env) + logs.debug('Executing with env: {}'.format(env), settings) + + result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=env) if wait_output(settings, result): return types.Command(script, result.stdout.read().decode('utf-8'), result.stderr.read().decode('utf-8'))