How to use the thefuck.utils.get_closest function in thefuck

To help you get started, we’ve selected a few thefuck examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nvbn / thefuck / tests / test_utils.py View on Github external
def test_when_cant_match(self):
        assert 'status' == get_closest('st', ['status', 'reset'])
github nvbn / thefuck / thefuck / rules / grunt_task_not_found.py View on Github external
def get_new_command(command):
    misspelled_task = regex.findall(command.stdout)[0].split(':')[0]
    tasks = _get_all_tasks()
    fixed = get_closest(misspelled_task, tasks)
    return command.script.replace(' {}'.format(misspelled_task),
                                  ' {}'.format(fixed))
github nvbn / thefuck / thefuck / rules / brew_install.py View on Github external
def _get_similar_formula(formula_name):
    return get_closest(formula_name, _get_formulas(), cutoff=0.85)
github nvbn / thefuck / thefuck / rules / git_checkout.py View on Github external
def get_new_command(command):
    missing_file = re.findall(
        r"error: pathspec '([^']*)' "
        r"did not match any file\(s\) known to git", command.output)[0]
    closest_branch = utils.get_closest(missing_file, get_branches(),
                                       fallback_to_first=False)
    if closest_branch:
        return replace_argument(command.script, missing_file, closest_branch)
    elif command.script_parts[1] == 'checkout':
        return replace_argument(command.script, 'checkout', 'checkout -b')
    else:
        return shell.and_('git branch {}', '{}').format(
            missing_file, command.script)
github nvbn / thefuck / thefuck / rules / mercurial.py View on Github external
def get_new_command(command):
    script = command.script_parts[:]
    possibilities = extract_possibilities(command)
    script[1] = get_closest(script[1], possibilities)
    return ' '.join(script)
github nvbn / thefuck / thefuck / rules / npm_wrong_command.py View on Github external
def get_new_command(command):
    npm_commands = _get_available_commands(command.output)
    wrong_command = _get_wrong_command(command.script_parts)
    fixed = get_closest(wrong_command, npm_commands)
    return replace_argument(command.script, wrong_command, fixed)
github nvbn / thefuck / thefuck / rules / git_fix_stash.py View on Github external
def get_new_command(command):
    stash_cmd = command.script_parts[2]
    fixed = utils.get_closest(stash_cmd, stash_commands, fallback_to_first=False)

    if fixed is not None:
        return replace_argument(command.script, stash_cmd, fixed)
    else:
        cmd = command.script_parts[:]
        cmd.insert(2, 'save')
        return ' '.join(cmd)
github nvbn / thefuck / thefuck / rules / brew_unknown_command.py View on Github external
def match(command):
    is_proper_command = ('brew' in command.script and
                         'Unknown command' in command.output)

    if is_proper_command:
        broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)',
                                command.output)[0]
        return bool(get_closest(broken_cmd, _brew_commands()))
    return False