Merge branch 'master' into 682-instant-fuck-mode
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import six
|
||||
from ..logs import warn
|
||||
from ..shells import shell
|
||||
|
||||
|
||||
def print_alias(known_args):
|
||||
if six.PY2:
|
||||
warn("The Fuck will drop Python 2 support soon, more details "
|
||||
"https://github.com/nvbn/thefuck/issues/685")
|
||||
|
||||
if known_args.enable_experimental_instant_mode:
|
||||
if six.PY2:
|
||||
warn("Instant mode not supported with Python 2")
|
||||
alias = shell.app_alias(known_args.alias)
|
||||
else:
|
||||
alias = shell.instant_mode_alias(known_args.alias)
|
||||
else:
|
||||
alias = shell.app_alias(known_args.alias)
|
||||
|
||||
print(alias)
|
||||
@@ -0,0 +1,47 @@
|
||||
from pprint import pformat
|
||||
import os
|
||||
import sys
|
||||
from difflib import SequenceMatcher
|
||||
from .. import logs, types, const
|
||||
from ..conf import settings
|
||||
from ..corrector import get_corrected_commands
|
||||
from ..exceptions import EmptyCommand
|
||||
from ..ui import select_command
|
||||
from ..utils import get_alias, get_all_executables
|
||||
|
||||
|
||||
def _get_raw_command(known_args):
|
||||
if known_args.force_command:
|
||||
return known_args.force_command
|
||||
elif not os.environ.get('TF_HISTORY'):
|
||||
return known_args.command
|
||||
else:
|
||||
history = os.environ['TF_HISTORY'].split('\n')[::-1]
|
||||
alias = get_alias()
|
||||
executables = get_all_executables()
|
||||
for command in history:
|
||||
diff = SequenceMatcher(a=alias, b=command).ratio()
|
||||
if diff < const.DIFF_WITH_ALIAS or command in executables:
|
||||
return [command]
|
||||
|
||||
|
||||
def fix_command(known_args):
|
||||
"""Fixes previous command. Used when `thefuck` called without arguments."""
|
||||
settings.init(known_args)
|
||||
with logs.debug_time('Total'):
|
||||
logs.debug(u'Run with settings: {}'.format(pformat(settings)))
|
||||
raw_command = _get_raw_command(known_args)
|
||||
|
||||
try:
|
||||
command = types.Command.from_raw_script(raw_command)
|
||||
except EmptyCommand:
|
||||
logs.debug('Empty command, nothing to do')
|
||||
return
|
||||
|
||||
corrected_commands = get_corrected_commands(command)
|
||||
selected_command = select_command(corrected_commands)
|
||||
|
||||
if selected_command:
|
||||
selected_command.run(command)
|
||||
else:
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,29 @@
|
||||
# Initialize output before importing any module, that can use colorama.
|
||||
from ..system import init_output
|
||||
|
||||
init_output()
|
||||
|
||||
import os # noqa: E402
|
||||
import sys # noqa: E402
|
||||
from .. import logs # noqa: E402
|
||||
from ..argument_parser import Parser # noqa: E402
|
||||
from ..utils import get_installation_info # noqa: E402
|
||||
from .alias import print_alias # noqa: E402
|
||||
from .fix_command import fix_command # noqa: E402
|
||||
|
||||
|
||||
def main():
|
||||
parser = Parser()
|
||||
known_args = parser.parse(sys.argv)
|
||||
|
||||
if known_args.help:
|
||||
parser.print_help()
|
||||
elif known_args.version:
|
||||
logs.version(get_installation_info().version,
|
||||
sys.version.split()[0])
|
||||
elif known_args.command or 'TF_HISTORY' in os.environ:
|
||||
fix_command(known_args)
|
||||
elif known_args.alias:
|
||||
print_alias(known_args)
|
||||
else:
|
||||
parser.print_usage()
|
||||
@@ -1,5 +1,5 @@
|
||||
# Initialize output before importing any module, that can use colorama.
|
||||
from .system import init_output
|
||||
from ..system import init_output
|
||||
|
||||
init_output()
|
||||
|
||||
@@ -8,11 +8,11 @@ import json # noqa: E402
|
||||
import time # noqa: E402
|
||||
import six # noqa: E402
|
||||
from psutil import Process # noqa: E402
|
||||
from . import logs, const # noqa: E402
|
||||
from .shells import shell # noqa: E402
|
||||
from .conf import settings # noqa: E402
|
||||
from .system import Path # noqa: E402
|
||||
from .utils import get_cache_dir # noqa: E402
|
||||
from .. import logs, const # noqa: E402
|
||||
from ..shells import shell # noqa: E402
|
||||
from ..conf import settings # noqa: E402
|
||||
from ..system import Path # noqa: E402
|
||||
from ..utils import get_cache_dir # noqa: E402
|
||||
|
||||
|
||||
def _get_shell_pid():
|
||||
@@ -1,87 +0,0 @@
|
||||
# Initialize output before importing any module, that can use colorama.
|
||||
from .system import init_output
|
||||
|
||||
init_output()
|
||||
|
||||
from pprint import pformat # noqa: E402
|
||||
import os # noqa: E402
|
||||
import sys # noqa: E402
|
||||
from difflib import SequenceMatcher # noqa: E402
|
||||
import six # noqa: E402
|
||||
from . import logs, types, const # noqa: E402
|
||||
from .shells import shell # noqa: E402
|
||||
from .conf import settings # noqa: E402
|
||||
from .corrector import get_corrected_commands # noqa: E402
|
||||
from .exceptions import EmptyCommand # noqa: E402
|
||||
from .ui import select_command # noqa: E402
|
||||
from .argument_parser import Parser # noqa: E402
|
||||
from .utils import (get_installation_info, get_alias,
|
||||
get_all_executables) # noqa: E402
|
||||
from .logs import warn # noqa: E402
|
||||
|
||||
|
||||
def _get_raw_command(known_args):
|
||||
if known_args.force_command:
|
||||
return known_args.force_command
|
||||
elif 'TF_HISTORY' not in os.environ:
|
||||
return known_args.command
|
||||
else:
|
||||
history = os.environ['TF_HISTORY'].split('\n')[::-1]
|
||||
alias = get_alias()
|
||||
executables = get_all_executables()
|
||||
for command in history:
|
||||
diff = SequenceMatcher(a=alias, b=command).ratio()
|
||||
if diff < const.DIFF_WITH_ALIAS or command in executables:
|
||||
return [command]
|
||||
|
||||
|
||||
def fix_command(known_args):
|
||||
"""Fixes previous command. Used when `thefuck` called without arguments."""
|
||||
settings.init(known_args)
|
||||
with logs.debug_time('Total'):
|
||||
logs.debug(u'Run with settings: {}'.format(pformat(settings)))
|
||||
raw_command = _get_raw_command(known_args)
|
||||
|
||||
try:
|
||||
command = types.Command.from_raw_script(raw_command)
|
||||
except EmptyCommand:
|
||||
logs.debug('Empty command, nothing to do')
|
||||
return
|
||||
|
||||
corrected_commands = get_corrected_commands(command)
|
||||
selected_command = select_command(corrected_commands)
|
||||
|
||||
if selected_command:
|
||||
selected_command.run(command)
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
parser = Parser()
|
||||
known_args = parser.parse(sys.argv)
|
||||
|
||||
if known_args.help:
|
||||
parser.print_help()
|
||||
elif known_args.version:
|
||||
logs.version(get_installation_info().version,
|
||||
sys.version.split()[0])
|
||||
elif known_args.command or 'TF_HISTORY' in os.environ:
|
||||
fix_command(known_args)
|
||||
elif known_args.alias:
|
||||
if six.PY2:
|
||||
warn("The Fuck will drop Python 2 support soon, more details "
|
||||
"https://github.com/nvbn/thefuck/issues/685")
|
||||
|
||||
if known_args.enable_experimental_instant_mode:
|
||||
if six.PY2:
|
||||
warn("Instant mode not supported with Python 2")
|
||||
alias = shell.app_alias(known_args.alias)
|
||||
else:
|
||||
alias = shell.instant_mode_alias(known_args.alias)
|
||||
else:
|
||||
alias = shell.app_alias(known_args.alias)
|
||||
|
||||
print(alias)
|
||||
else:
|
||||
parser.print_usage()
|
||||
+1
-1
@@ -75,7 +75,7 @@ def default_settings(params):
|
||||
Usage:
|
||||
|
||||
@default_settings({'apt': '/usr/bin/apt'})
|
||||
def match(command, settings):
|
||||
def match(command):
|
||||
print(settings.apt)
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user