1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 12:06:04 +00:00

Merge pull request #500 from scorphus/history-merge

#495: Alter history only when configured to do so
This commit is contained in:
Vladimir Iakovlev 2016-05-03 13:18:12 +03:00
commit c3709682d5
2 changed files with 16 additions and 4 deletions

View File

@ -74,6 +74,14 @@ class TestFish(object):
assert 'TF_ALIAS=fuck PYTHONIOENCODING' in shell.app_alias('fuck')
assert 'PYTHONIOENCODING=utf-8 thefuck' in shell.app_alias('fuck')
def test_app_alias_alter_history(self, settings, shell):
settings.alter_history = True
assert 'history --delete' in shell.app_alias('FUCK')
assert 'history --merge' in shell.app_alias('FUCK')
settings.alter_history = False
assert 'history --delete' not in shell.app_alias('FUCK')
assert 'history --merge' not in shell.app_alias('FUCK')
def test_get_history(self, history_lines, shell):
history_lines(['- cmd: ls', ' when: 1432613911',
'- cmd: rm', ' when: 1432613916'])

View File

@ -4,6 +4,7 @@ import os
import sys
import six
from .. import logs
from ..conf import settings
from ..utils import DEVNULL, memoize, cache
from .generic import Generic
@ -18,17 +19,20 @@ class Fish(Generic):
return default
def app_alias(self, fuck):
if settings.alter_history:
alter_history = (' history --delete $fucked_up_command\n'
' history --merge ^ /dev/null\n')
else:
alter_history = ''
# It is VERY important to have the variables declared WITHIN the alias
return ('function {0} -d "Correct your previous console command"\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'
' if [ "$unfucked_command" != "" ]\n'
' eval $unfucked_command\n'
' history --delete $fucked_up_command\n'
' history --merge ^ /dev/null\n'
' eval $unfucked_command\n{1}'
' end\n'
'end').format(fuck)
'end').format(fuck, alter_history)
@memoize
@cache('.config/fish/config.fish', '.config/fish/functions')