#475: Try to use already used executable in no_command

This commit is contained in:
nvbn
2016-03-13 15:10:37 +03:00
parent 8b1f078e27
commit 251b69b5a0
6 changed files with 107 additions and 61 deletions
+21
View File
@@ -269,3 +269,24 @@ def get_installation_info():
def get_alias():
return os.environ.get('TF_ALIAS', 'fuck')
@memoize
def get_valid_history_without_current(command):
def _not_corrected(history, tf_alias):
"""Returns all lines from history except that comes before `fuck`."""
previous = None
for line in history:
if previous is not None and line != tf_alias:
yield previous
previous = line
if history:
yield history[-1]
from thefuck.shells import shell
history = shell.get_history()
tf_alias = get_alias()
executables = get_all_executables()
return [line for line in _not_corrected(history, tf_alias)
if not line.startswith(tf_alias) and not line == command.script
and line.split(' ')[0] in executables]