From 4af7dc2748d95d54ce7ef993e8e6273b9f7f49bd Mon Sep 17 00:00:00 2001 From: mcarton Date: Mon, 22 Feb 2016 14:39:30 +0100 Subject: [PATCH] =?UTF-8?q?Let=20bash=20handle=20bash=E2=80=99s=20history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/shells/test_bash.py | 12 ++---------- thefuck/shells/bash.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/shells/test_bash.py b/tests/shells/test_bash.py index 13f3fdda..56591a5a 100644 --- a/tests/shells/test_bash.py +++ b/tests/shells/test_bash.py @@ -31,14 +31,6 @@ class TestBash(object): def test_to_shell(self, shell): assert shell.to_shell('pwd') == 'pwd' - @pytest.mark.parametrize('entry, entry_utf8', [ - ('ls', 'ls\n'), - (u'echo café', 'echo café\n')]) - def test_put_to_history(self, entry, entry_utf8, builtins_open, shell): - shell.put_to_history(entry) - builtins_open.return_value.__enter__.return_value. \ - write.assert_called_once_with(entry_utf8) - def test_and_(self, shell): assert shell.and_('ls', 'cd') == 'ls && cd' @@ -52,8 +44,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=fuck PYTHONIOENCODING' in shell.app_alias('fuck') - assert 'PYTHONIOENCODING=utf-8 thefuck' in shell.app_alias('fuck') + assert 'TF_ALIAS=fuck' in shell.app_alias('fuck') + assert 'PYTHONIOENCODING=utf-8' in shell.app_alias('fuck') def test_get_history(self, history_lines, shell): history_lines(['ls', 'rm']) diff --git a/thefuck/shells/bash.py b/thefuck/shells/bash.py index 9e7a1c4b..52db1c4b 100644 --- a/thefuck/shells/bash.py +++ b/thefuck/shells/bash.py @@ -6,9 +6,11 @@ from .generic import Generic class Bash(Generic): def app_alias(self, fuck): - return "alias {0}='eval " \ - "$(TF_ALIAS={0} PYTHONIOENCODING=utf-8 thefuck $(fc -ln -1));" \ - " history -r'".format(fuck) + return "TF_ALIAS={0}" \ + " alias {0}='PYTHONIOENCODING=utf-8" \ + " TF_CMD=$(thefuck $(fc -ln -1)) && " \ + " eval $TF_CMD &&" \ + " history -s $TF_CMD'".format(fuck) def _parse_alias(self, alias): name, value = alias.replace('alias ', '', 1).split('=', 1) @@ -32,6 +34,10 @@ class Bash(Generic): def _get_history_line(self, command_script): return u'{}\n'.format(command_script) + def put_to_history(self, command_script): + # handled by the alias + pass + def how_to_configure(self): if os.path.join(os.path.expanduser('~'), '.bashrc'): config = '~/.bashrc'