Skip to content

Commit

Permalink
Merge pull request #431 from nvbn/428-readonly-history
Browse files Browse the repository at this point in the history
#428: Don't fail when history is readonly
  • Loading branch information
nvbn committed Jan 13, 2016
2 parents 8b05f6d + d53240b commit 6e22b9e
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions thefuck/shells.py
Expand Up @@ -10,13 +10,14 @@
import io
import os
import shlex
import sys
import six
from .utils import DEVNULL, memoize, cache
from .conf import settings
from . import logs


class Generic(object):

def get_aliases(self):
return {}

Expand Down Expand Up @@ -69,8 +70,8 @@ def get_history(self):
lines = lines[-settings.history_limit:]

for line in lines:
prepared = self._script_from_history(line)\
.strip()
prepared = self._script_from_history(line) \
.strip()
if prepared:
yield prepared

Expand Down Expand Up @@ -117,9 +118,9 @@ def _parse_alias(self, alias):
def get_aliases(self):
proc = Popen(['bash', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
return dict(
self._parse_alias(alias)
for alias in proc.stdout.read().decode('utf-8').split('\n')
if alias and '=' in alias)
self._parse_alias(alias)
for alias in proc.stdout.read().decode('utf-8').split('\n')
if alias and '=' in alias)

def _get_history_file_name(self):
return os.environ.get("HISTFILE",
Expand All @@ -139,7 +140,6 @@ def how_to_configure(self):


class Fish(Generic):

def _get_overridden_aliases(self):
overridden_aliases = os.environ.get('TF_OVERRIDDEN_ALIASES', '').strip()
if overridden_aliases:
Expand Down Expand Up @@ -219,9 +219,9 @@ def _parse_alias(self, alias):
def get_aliases(self):
proc = Popen(['zsh', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
return dict(
self._parse_alias(alias)
for alias in proc.stdout.read().decode('utf-8').split('\n')
if alias and '=' in alias)
self._parse_alias(alias)
for alias in proc.stdout.read().decode('utf-8').split('\n')
if alias and '=' in alias)

def _get_history_file_name(self):
return os.environ.get("HISTFILE",
Expand Down Expand Up @@ -254,9 +254,9 @@ def _parse_alias(self, alias):
def get_aliases(self):
proc = Popen(['tcsh', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
return dict(
self._parse_alias(alias)
for alias in proc.stdout.read().decode('utf-8').split('\n')
if alias and '\t' in alias)
self._parse_alias(alias)
for alias in proc.stdout.read().decode('utf-8').split('\n')
if alias and '\t' in alias)

def _get_history_file_name(self):
return os.environ.get("HISTFILE",
Expand Down Expand Up @@ -303,7 +303,10 @@ def thefuck_alias():


def put_to_history(command):
return _get_shell().put_to_history(command)
try:
return _get_shell().put_to_history(command)
except IOError:
logs.exception("Can't update history", sys.exc_info())


def and_(*commands):
Expand Down

0 comments on commit 6e22b9e

Please sign in to comment.