⚠️ #442: Change history only on shell side
This commit is contained in:
+10
-9
@@ -1,16 +1,21 @@
|
||||
from subprocess import Popen, PIPE
|
||||
import os
|
||||
from ..conf import settings
|
||||
from ..utils import DEVNULL, memoize, cache
|
||||
from .generic import Generic
|
||||
|
||||
|
||||
class Bash(Generic):
|
||||
def app_alias(self, 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)
|
||||
alias = "TF_ALIAS={0}" \
|
||||
" alias {0}='PYTHONIOENCODING=utf-8" \
|
||||
" TF_CMD=$(thefuck $(fc -ln -1)) && " \
|
||||
" eval $TF_CMD".format(fuck)
|
||||
|
||||
if settings.alter_history:
|
||||
return alias + " && history -s $TF_CMD'"
|
||||
else:
|
||||
return alias + "'"
|
||||
|
||||
def _parse_alias(self, alias):
|
||||
name, value = alias.replace('alias ', '', 1).split('=', 1)
|
||||
@@ -34,10 +39,6 @@ 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'
|
||||
|
||||
@@ -2,11 +2,8 @@ import io
|
||||
import os
|
||||
import shlex
|
||||
import six
|
||||
import sys
|
||||
|
||||
from ..utils import memoize
|
||||
from ..conf import settings
|
||||
from .. import logs
|
||||
|
||||
|
||||
class Generic(object):
|
||||
@@ -39,23 +36,6 @@ class Generic(object):
|
||||
def _get_history_line(self, command_script):
|
||||
return ''
|
||||
|
||||
def put_to_history(self, command):
|
||||
try:
|
||||
return self._put_to_history(command)
|
||||
except IOError:
|
||||
logs.exception("Can't update history", sys.exc_info())
|
||||
|
||||
def _put_to_history(self, command_script):
|
||||
"""Puts command script to shell history."""
|
||||
history_file_name = self._get_history_file_name()
|
||||
if os.path.isfile(history_file_name):
|
||||
with open(history_file_name, 'a') as history:
|
||||
entry = self._get_history_line(command_script)
|
||||
if six.PY2:
|
||||
history.write(entry.encode('utf-8'))
|
||||
else:
|
||||
history.write(entry)
|
||||
|
||||
@memoize
|
||||
def get_history(self):
|
||||
return list(self._get_history_lines())
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
from subprocess import Popen, PIPE
|
||||
from time import time
|
||||
import os
|
||||
from ..conf import settings
|
||||
from ..utils import DEVNULL, memoize, cache
|
||||
from .generic import Generic
|
||||
|
||||
|
||||
class Zsh(Generic):
|
||||
def app_alias(self, fuck):
|
||||
return "alias {0}='eval $(TF_ALIAS={0} PYTHONIOENCODING=utf-8" \
|
||||
" thefuck $(fc -ln -1 | tail -n 1));" \
|
||||
" fc -R'".format(fuck)
|
||||
alias = "alias {0}='TF_ALIAS={0} PYTHONIOENCODING=utf-8" \
|
||||
" TF_CMD=$(thefuck $(fc -ln -1 | tail -n 1)) &&" \
|
||||
" eval $TF_CMD".format(fuck)
|
||||
|
||||
if settings.alter_history:
|
||||
return alias + " && print -s $TF_CMD'"
|
||||
else:
|
||||
return alias + "'"
|
||||
|
||||
def _parse_alias(self, alias):
|
||||
name, value = alias.split('=', 1)
|
||||
|
||||
@@ -279,8 +279,6 @@ class CorrectedCommand(object):
|
||||
"""
|
||||
if self.side_effect:
|
||||
compatibility_call(self.side_effect, old_cmd, self.script)
|
||||
if settings.alter_history:
|
||||
shell.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-<')))
|
||||
|
||||
Reference in New Issue
Block a user