Merge branch 'fish-put-to-history' of https://github.com/scorphus/thefuck into scorphus-fish-put-to-history

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
This commit is contained in:
nvbn
2016-04-22 03:14:31 +03:00
parent 9f421a17e5
commit d5ae3a6b41
4 changed files with 34 additions and 0 deletions
+20
View File
@@ -1,6 +1,9 @@
from subprocess import Popen, PIPE
from time import time
import os
import sys
import six
from .. import logs
from ..utils import DEVNULL, memoize, cache
from .generic import Generic
@@ -65,3 +68,20 @@ class Fish(Generic):
def how_to_configure(self):
return (r"eval (thefuck --alias | tr '\n' ';')",
'~/.config/fish/config.fish')
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)
+3
View File
@@ -81,3 +81,6 @@ class Generic(object):
def _script_from_history(self, line):
return line
def put_to_history(self, command):
pass
+2
View File
@@ -280,6 +280,8 @@ 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!!')))