Skip to content

Commit

Permalink
#422: Add alter_history settings option
Browse files Browse the repository at this point in the history
  • Loading branch information
nvbn committed Jan 13, 2016
1 parent f0f49c1 commit 2f35349
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -282,7 +282,8 @@ The Fuck has a few settings parameters which can be changed in `$XDG_CONFIG_HOME
* `no_colors` – disable colored output;
* `priority` – dict with rules priorities, rule with lower `priority` will be matched first;
* `debug` – enables debug output, by default `False`;
* `history_limit` – numeric value of how many history commands will be scanned, like `2000`;
* `history_limit` – numeric value of how many history commands will be scanned, like `2000`;
* `alter_history` – push fixed command to history, by default `True`.

Example of `settings.py`:

Expand All @@ -306,7 +307,8 @@ Or via environment variables:
* `THEFUCK_PRIORITY` – priority of the rules, like `no_command=9999:apt_get=100`,
rule with lower `priority` will be matched first;
* `THEFUCK_DEBUG` – enables debug output, `true/false`;
* `THEFUCK_HISTORY_LIMIT` – how many history commands will be scanned, like `2000`.
* `THEFUCK_HISTORY_LIMIT` – how many history commands will be scanned, like `2000`;
* `THEFUCK_ALTER_HISTORY` – push fixed command to history `true/false`.

For example:

Expand Down
9 changes: 6 additions & 3 deletions thefuck/conf.py
Expand Up @@ -17,16 +17,18 @@
'debug': False,
'priority': {},
'history_limit': None,
'alter_history': True,
'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}}

ENV_TO_ATTR = {'THEFUCK_RULES': 'rules',
'THEFUCK_EXCLUDE_RULES': 'exclude_rules',
'THEFUCK_WAIT_COMMAND': 'wait_command',
'THEFUCK_REQUIRE_CONFIRMATION': 'require_confirmation',
'THEFUCK_NO_COLORS': 'no_colors',
'THEFUCK_PRIORITY': 'priority',
'THEFUCK_DEBUG': 'debug',
'THEFUCK_HISTORY_LIMIT': 'history_limit'}
'THEFUCK_PRIORITY': 'priority',
'THEFUCK_HISTORY_LIMIT': 'history_limit',
'THEFUCK_ALTER_HISTORY': 'alter_history'}

SETTINGS_HEADER = u"""# The Fuck settings file
#
Expand Down Expand Up @@ -126,7 +128,8 @@ def _val_from_env(self, env, attr):
return dict(self._priority_from_env(val))
elif attr == 'wait_command':
return int(val)
elif attr in ('require_confirmation', 'no_colors', 'debug'):
elif attr in ('require_confirmation', 'no_colors', 'debug',
'alter_history'):
return val.lower() == 'true'
elif attr == 'history_limit':
return int(val)
Expand Down
17 changes: 9 additions & 8 deletions thefuck/types.py
Expand Up @@ -32,20 +32,20 @@ def script_parts(self):
self._script_parts = shells.split_command(self.script)
except Exception:
logs.debug(u"Can't split command script {} because:\n {}".format(
self, sys.exc_info()))
self, sys.exc_info()))
self._script_parts = None
return self._script_parts

def __eq__(self, other):
if isinstance(other, Command):
return (self.script, self.stdout, self.stderr) \
== (other.script, other.stdout, other.stderr)
== (other.script, other.stdout, other.stderr)
else:
return False

def __repr__(self):
return u'Command(script={}, stdout={}, stderr={})'.format(
self.script, self.stdout, self.stderr)
self.script, self.stdout, self.stderr)

def update(self, **kwargs):
"""Returns new command with replaced fields.
Expand Down Expand Up @@ -166,9 +166,9 @@ def __repr__(self):
return 'Rule(name={}, match={}, get_new_command={}, ' \
'enabled_by_default={}, side_effect={}, ' \
'priority={}, requires_output)'.format(
self.name, self.match, self.get_new_command,
self.enabled_by_default, self.side_effect,
self.priority, self.requires_output)
self.name, self.match, self.get_new_command,
self.enabled_by_default, self.side_effect,
self.priority, self.requires_output)

@classmethod
def from_path(cls, path):
Expand Down Expand Up @@ -268,7 +268,7 @@ def __hash__(self):

def __repr__(self):
return u'CorrectedCommand(script={}, side_effect={}, priority={})'.format(
self.script, self.side_effect, self.priority)
self.script, self.side_effect, self.priority)

def run(self, old_cmd):
"""Runs command from rule for passed command.
Expand All @@ -278,6 +278,7 @@ def run(self, old_cmd):
"""
if self.side_effect:
compatibility_call(self.side_effect, old_cmd, self.script)
shells.put_to_history(self.script)
if settings.alter_history:
shells.put_to_history(self.script)
# This depends on correct setting of PYTHONIOENCODING by the alias:
print(self.script)

0 comments on commit 2f35349

Please sign in to comment.