diff --git a/tests/test_shells.py b/tests/test_shells.py index 060419f4..1cea2fb9 100644 --- a/tests/test_shells.py +++ b/tests/test_shells.py @@ -50,8 +50,8 @@ class TestGeneric(object): assert 'alias fuck' in shell.app_alias('fuck') assert 'alias FUCK' in shell.app_alias('FUCK') assert 'thefuck' in shell.app_alias('fuck') - assert 'TF_ALIAS' in shell.app_alias('fuck') - assert 'PYTHONIOENCODING=utf-8' in shell.app_alias('fuck') + assert 'TF_ALIAS=fuck PYTHONIOENCODING' in shell.app_alias('fuck') + assert 'PYTHONIOENCODING=utf-8 thefuck' in shell.app_alias('fuck') def test_get_history(self, history_lines, shell): history_lines(['ls', 'rm']) @@ -112,8 +112,8 @@ class TestBash(object): assert 'alias fuck' in shell.app_alias('fuck') assert 'alias FUCK' in shell.app_alias('FUCK') assert 'thefuck' in shell.app_alias('fuck') - assert 'TF_ALIAS' in shell.app_alias('fuck') - assert 'PYTHONIOENCODING=utf-8' in shell.app_alias('fuck') + assert 'TF_ALIAS=fuck PYTHONIOENCODING' in shell.app_alias('fuck') + assert 'PYTHONIOENCODING=utf-8 thefuck' in shell.app_alias('fuck') def test_get_history(self, history_lines, shell): history_lines(['ls', 'rm']) @@ -193,8 +193,8 @@ class TestFish(object): assert 'function fuck' in shell.app_alias('fuck') assert 'function FUCK' in shell.app_alias('FUCK') assert 'thefuck' in shell.app_alias('fuck') - assert 'TF_ALIAS' in shell.app_alias('fuck') - assert 'PYTHONIOENCODING=utf-8' in shell.app_alias('fuck') + assert 'TF_ALIAS=fuck PYTHONIOENCODING' in shell.app_alias('fuck') + assert 'PYTHONIOENCODING=utf-8 thefuck' in shell.app_alias('fuck') def test_get_history(self, history_lines, shell): history_lines(['- cmd: ls', ' when: 1432613911', @@ -252,8 +252,8 @@ class TestZsh(object): assert 'alias fuck' in shell.app_alias('fuck') assert 'alias FUCK' in shell.app_alias('FUCK') assert 'thefuck' in shell.app_alias('fuck') - assert 'TF_ALIAS' in shell.app_alias('fuck') - assert 'PYTHONIOENCODING=utf-8' in shell.app_alias('fuck') + assert 'TF_ALIAS=fuck PYTHONIOENCODING' in shell.app_alias('fuck') + assert 'PYTHONIOENCODING=utf-8 thefuck' in shell.app_alias('fuck') def test_get_history(self, history_lines, shell): history_lines([': 1432613911:0;ls', ': 1432613916:0;rm']) diff --git a/thefuck/shells.py b/thefuck/shells.py index f78d2575..9bd7fd3a 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -38,8 +38,8 @@ class Generic(object): return command_script def app_alias(self, fuck): - return "alias {0}='TF_ALIAS={0} PYTHONIOENCODING=utf-8 " \ - "eval $(thefuck $(fc -ln -1))'".format(fuck) + return "alias {0}='eval $(TF_ALIAS={0} PYTHONIOENCODING=utf-8 " \ + "thefuck $(fc -ln -1))'".format(fuck) def _get_history_file_name(self): return '' @@ -103,8 +103,8 @@ class Generic(object): class Bash(Generic): def app_alias(self, fuck): - return "TF_ALIAS={0} alias {0}='PYTHONIOENCODING=utf-8 " \ - "eval $(thefuck $(fc -ln -1));" \ + return "alias {0}='eval " \ + "$(TF_ALIAS={0} PYTHONIOENCODING=utf-8 thefuck $(fc -ln -1));" \ " history -r'".format(fuck) def _parse_alias(self, alias): @@ -152,7 +152,7 @@ class Fish(Generic): ' set -l exit_code $status\n' ' set -l fucked_up_command $history[1]\n' ' env TF_ALIAS={0} PYTHONIOENCODING=utf-8' - ' thefuck $fucked_up_command | read -l unfucked_command\n' + ' thefuck $fucked_up_command | read -l unfucked_command\n' ' if [ "$unfucked_command" != "" ]\n' ' eval $unfucked_command\n' ' if test $exit_code -ne 0\n' @@ -203,9 +203,8 @@ class Fish(Generic): class Zsh(Generic): def app_alias(self, fuck): - return "TF_ALIAS={0}" \ - " alias {0}='PYTHONIOENCODING=utf-8 " \ - "eval $(thefuck $(fc -ln -1 | tail -n 1));" \ + return "alias {0}='eval $(TF_ALIAS={0} PYTHONIOENCODING=utf-8" \ + " thefuck $(fc -ln -1 | tail -n 1));" \ " fc -R'".format(fuck) def _parse_alias(self, alias): diff --git a/thefuck/types.py b/thefuck/types.py index 89c9d862..f5864658 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -281,4 +281,6 @@ class CorrectedCommand(object): if settings.alter_history: shells.put_to_history(self.script) # This depends on correct setting of PYTHONIOENCODING by the alias: + logs.debug(u'PYTHONIOENCODING: {}'.format( + os.environ.get('PYTHONIOENCODING', '>-not-set-<'))) print(self.script)