+5
-1
@@ -16,6 +16,7 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES,
|
||||
'no_colors': False,
|
||||
'debug': False,
|
||||
'priority': {},
|
||||
'history_limit': None,
|
||||
'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}}
|
||||
|
||||
ENV_TO_ATTR = {'THEFUCK_RULES': 'rules',
|
||||
@@ -24,7 +25,8 @@ ENV_TO_ATTR = {'THEFUCK_RULES': 'rules',
|
||||
'THEFUCK_REQUIRE_CONFIRMATION': 'require_confirmation',
|
||||
'THEFUCK_NO_COLORS': 'no_colors',
|
||||
'THEFUCK_PRIORITY': 'priority',
|
||||
'THEFUCK_DEBUG': 'debug'}
|
||||
'THEFUCK_DEBUG': 'debug',
|
||||
'THEFUCK_HISTORY_LIMIT': 'history_limit'}
|
||||
|
||||
SETTINGS_HEADER = u"""# The Fuck settings file
|
||||
#
|
||||
@@ -126,6 +128,8 @@ class Settings(dict):
|
||||
return int(val)
|
||||
elif attr in ('require_confirmation', 'no_colors', 'debug'):
|
||||
return val.lower() == 'true'
|
||||
elif attr == 'history_limit':
|
||||
return int(val)
|
||||
else:
|
||||
return val
|
||||
|
||||
|
||||
+8
-10
@@ -12,6 +12,7 @@ import os
|
||||
import shlex
|
||||
import six
|
||||
from .utils import DEVNULL, memoize, cache
|
||||
from .conf import settings
|
||||
|
||||
|
||||
class Generic(object):
|
||||
@@ -52,21 +53,18 @@ class Generic(object):
|
||||
with open(history_file_name, 'a') as history:
|
||||
history.write(self._get_history_line(command_script))
|
||||
|
||||
def _script_from_history(self, line):
|
||||
"""Returns prepared history line.
|
||||
|
||||
Should return a blank line if history line is corrupted or empty.
|
||||
|
||||
"""
|
||||
return ''
|
||||
|
||||
def get_history(self):
|
||||
"""Returns list of history entries."""
|
||||
history_file_name = self._get_history_file_name()
|
||||
if os.path.isfile(history_file_name):
|
||||
with io.open(history_file_name, 'r',
|
||||
encoding='utf-8', errors='ignore') as history:
|
||||
for line in history:
|
||||
encoding='utf-8', errors='ignore') as history_file:
|
||||
|
||||
lines = history_file.readlines()
|
||||
if settings.history_limit:
|
||||
lines = lines[-settings.history_limit:]
|
||||
|
||||
for line in lines:
|
||||
prepared = self._script_from_history(line)\
|
||||
.strip()
|
||||
if prepared:
|
||||
|
||||
Reference in New Issue
Block a user