1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-10-30 06:34:09 +00:00

#495: Merge history only when alter_history is set

This commit is contained in:
Pablo Santiago Blum de Aguiar
2016-04-29 23:21:28 -03:00
parent f74bbb7a9a
commit d1f55603fe
2 changed files with 13 additions and 3 deletions

View File

@@ -74,6 +74,12 @@ class TestFish(object):
assert 'TF_ALIAS=fuck PYTHONIOENCODING' 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 'PYTHONIOENCODING=utf-8 thefuck' in shell.app_alias('fuck')
def test_app_alias_history_merge(self, settings, shell):
settings.alter_history = True
assert 'history --merge' in shell.app_alias('FUCK')
settings.alter_history = False
assert 'history --merge' not in shell.app_alias('FUCK')
def test_get_history(self, history_lines, shell): def test_get_history(self, history_lines, shell):
history_lines(['- cmd: ls', ' when: 1432613911', history_lines(['- cmd: ls', ' when: 1432613911',
'- cmd: rm', ' when: 1432613916']) '- cmd: rm', ' when: 1432613916'])

View File

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