⚠️ Remove settings param from rules match, get_new_command and side_effect

This commit is contained in:
nvbn
2015-09-07 13:00:29 +03:00
parent 382eb8b86c
commit df4d2cc88d
154 changed files with 535 additions and 465 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ from imp import load_source
from pathlib import Path
from .conf import settings, DEFAULT_PRIORITY
from .types import Rule, CorrectedCommand, SortedCorrectedCommandsSequence
from .utils import compatibility_call
from . import logs
@@ -49,14 +50,14 @@ def is_rule_match(command, rule):
try:
with logs.debug_time(u'Trying rule: {};'.format(rule.name)):
if rule.match(command, settings):
if compatibility_call(rule.match, command):
return True
except Exception:
logs.rule_failed(rule, sys.exc_info())
def make_corrected_commands(command, rule):
new_commands = rule.get_new_command(command, settings)
new_commands = compatibility_call(rule.get_new_command, command)
if not isinstance(new_commands, list):
new_commands = (new_commands,)
for n, new_command in enumerate(new_commands):
+2 -1
View File
@@ -13,6 +13,7 @@ import six
from . import logs, types, shells
from .conf import initialize_settings_file, init_settings, settings
from .corrector import get_corrected_commands
from .utils import compatibility_call
from .ui import select_command
@@ -77,7 +78,7 @@ def get_command(args):
def run_command(old_cmd, command):
"""Runs command from rule for passed command."""
if command.side_effect:
command.side_effect(old_cmd, command.script, settings)
compatibility_call(command.side_effect, old_cmd, command.script)
shells.put_to_history(command.script)
print(command.script)
+2 -2
View File
@@ -20,11 +20,11 @@ def get_package(command):
return None
def match(command, settings):
def match(command):
return 'not found' in command.stderr and get_package(command.script)
def get_new_command(command, settings):
def get_new_command(command):
name = get_package(command.script)
formatme = shells.and_('sudo apt-get install {}', '{}')
return formatme.format(name, command.script)
+2 -2
View File
@@ -3,9 +3,9 @@ from thefuck.utils import for_app
@for_app('apt-get')
def match(command, settings):
def match(command):
return command.script.startswith('apt-get search')
def get_new_command(command, settings):
def get_new_command(command):
return re.sub(r'^apt-get', 'apt-cache', command.script)
+2 -2
View File
@@ -24,7 +24,7 @@ def _get_similar_formula(formula_name):
return get_closest(formula_name, _get_formulas(), 1, 0.85)
def match(command, settings):
def match(command):
is_proper_command = ('brew install' in command.script and
'No available formula' in command.stderr)
@@ -35,7 +35,7 @@ def match(command, settings):
return False
def get_new_command(command, settings):
def get_new_command(command):
not_exist_formula = re.findall(r'Error: No available formula for ([a-z]+)',
command.stderr)[0]
exist_formula = _get_similar_formula(not_exist_formula)
+2 -2
View File
@@ -63,7 +63,7 @@ def _brew_commands():
'doctor', 'create', 'edit']
def match(command, settings):
def match(command):
is_proper_command = ('brew' in command.script and
'Unknown command' in command.stderr)
@@ -74,7 +74,7 @@ def match(command, settings):
return False
def get_new_command(command, settings):
def get_new_command(command):
broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)',
command.stderr)[0]
return replace_command(command, broken_cmd, _brew_commands())
+2 -2
View File
@@ -6,9 +6,9 @@
# It currently upgrades all formula but this will soon change to require '--all'.
def match(command, settings):
def match(command):
return command.script == 'brew upgrade'
def get_new_command(command, settings):
def get_new_command(command):
return command.script + ' --all'
+2 -2
View File
@@ -1,6 +1,6 @@
def match(command, settings):
def match(command):
return command.script == 'cargo'
def get_new_command(command, settings):
def get_new_command(command):
return 'cargo build'
+2 -2
View File
@@ -3,12 +3,12 @@ from thefuck.utils import replace_argument, for_app
@for_app('cargo')
def match(command, settings):
def match(command):
return ('No such subcommand' in command.stderr
and 'Did you mean' in command.stderr)
def get_new_command(command, settings):
def get_new_command(command):
broken = command.script.split()[1]
fix = re.findall(r'Did you mean `([^`]*)`', command.stderr)[0]
+3 -3
View File
@@ -18,7 +18,7 @@ def _get_sub_dirs(parent):
@sudo_support
@for_app('cd')
def match(command, settings):
def match(command):
"""Match function copied from cd_mkdir.py"""
return (command.script.startswith('cd ')
and ('no such file or directory' in command.stderr.lower()
@@ -26,7 +26,7 @@ def match(command, settings):
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
"""
Attempt to rebuild the path string by spellchecking the directories.
If it fails (i.e. no directories are a close enough match), then it
@@ -47,7 +47,7 @@ def get_new_command(command, settings):
if best_matches:
cwd = os.path.join(cwd, best_matches[0])
else:
return cd_mkdir.get_new_command(command, settings)
return cd_mkdir.get_new_command(command)
return 'cd "{0}"'.format(cwd)
+2 -2
View File
@@ -6,12 +6,12 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
@for_app('cd')
def match(command, settings):
def match(command):
return (('no such file or directory' in command.stderr.lower()
or 'cd: can\'t cd to' in command.stderr.lower()))
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
repl = shells.and_('mkdir -p \\1', 'cd \\1')
return re.sub(r'^cd (.*)', repl, command.script)
+2 -2
View File
@@ -8,9 +8,9 @@
# cd..: command not found
def match(command, settings):
def match(command):
return command.script == 'cd..'
def get_new_command(command, settings):
def get_new_command(command):
return 'cd ..'
+2 -2
View File
@@ -3,12 +3,12 @@ from thefuck.utils import replace_argument, for_app
@for_app('composer')
def match(command, settings):
def match(command):
return (('did you mean this?' in command.stderr.lower()
or 'did you mean one of these?' in command.stderr.lower()))
def get_new_command(command, settings):
def get_new_command(command):
broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.stderr)[0]
new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.stderr)
if not new_cmd:
+2 -2
View File
@@ -5,11 +5,11 @@ from thefuck.utils import for_app
@sudo_support
@for_app('cp')
def match(command, settings):
def match(command):
stderr = command.stderr.lower()
return 'omitting directory' in stderr or 'is a directory' in stderr
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
return re.sub(r'^cp', 'cp -a', command.script)
+2 -2
View File
@@ -2,11 +2,11 @@ from thefuck.utils import for_app
@for_app(['g++', 'clang++'])
def match(command, settings):
def match(command):
return ('This file requires compiler and library support for the '
'ISO C++ 2011 standard.' in command.stderr or
'-Wc++11-extensions' in command.stderr)
def get_new_command(command, settings):
def get_new_command(command):
return command.script + ' -std=c++11'
+3 -3
View File
@@ -25,18 +25,18 @@ def _tar_file(cmd):
@for_app('tar')
def match(command, settings):
def match(command):
return ('-C' not in command.script
and _is_tar_extract(command.script)
and _tar_file(command.script) is not None)
def get_new_command(command, settings):
def get_new_command(command):
return shells.and_('mkdir -p {dir}', '{cmd} -C {dir}') \
.format(dir=_tar_file(command.script)[1], cmd=command.script)
def side_effect(old_cmd, command, settings):
def side_effect(old_cmd, command):
with tarfile.TarFile(_tar_file(old_cmd.script)[0]) as archive:
for file in archive.getnames():
os.remove(file)
+3 -3
View File
@@ -22,16 +22,16 @@ def _zip_file(command):
@for_app('unzip')
def match(command, settings):
def match(command):
return ('-d' not in command.script
and _is_bad_zip(_zip_file(command)))
def get_new_command(command, settings):
def get_new_command(command):
return '{} -d {}'.format(command.script, _zip_file(command)[:-4])
def side_effect(old_cmd, command, settings):
def side_effect(old_cmd, command):
with zipfile.ZipFile(_zip_file(old_cmd), 'r') as archive:
for file in archive.namelist():
os.remove(file)
+2 -2
View File
@@ -1,8 +1,8 @@
def match(command, settings):
def match(command):
return 'manage.py' in command.script and \
'migrate' in command.script \
and 'or pass --delete-ghost-migrations' in command.stderr
def get_new_command(command, settings):
def get_new_command(command):
return u'{} --delete-ghost-migrations'.format(command.script)
+2 -2
View File
@@ -1,8 +1,8 @@
def match(command, settings):
def match(command):
return 'manage.py' in command.script and \
'migrate' in command.script \
and '--merge: will just attempt the migration' in command.stderr
def get_new_command(command, settings):
def get_new_command(command):
return u'{} --merge'.format(command.script)
+2 -2
View File
@@ -7,7 +7,7 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
@for_app('docker')
def match(command, settings):
def match(command):
return 'is not a docker command' in command.stderr
@@ -21,7 +21,7 @@ def get_docker_commands():
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
wrong_command = re.findall(
r"docker: '(\w+)' is not a docker command.", command.stderr)[0]
return replace_command(command, wrong_command, get_docker_commands())
+2 -2
View File
@@ -1,10 +1,10 @@
def match(command, settings):
def match(command):
split_command = command.script.split()
return len(split_command) >= 2 and split_command[0] == split_command[1]
def get_new_command(command, settings):
def get_new_command(command):
return command.script[command.script.find(' ')+1:]
# it should be rare enough to actually have to type twice the same word, so
+2 -2
View File
@@ -5,11 +5,11 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command, settings):
def match(command):
return ('command not found' in command.stderr.lower()
and u' ' in command.script)
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
return re.sub(u' ', ' ', command.script)
+4 -3
View File
@@ -1,6 +1,7 @@
import re
import os
from thefuck.utils import memoize, default_settings
from thefuck.conf import settings
from thefuck import shells
@@ -50,7 +51,7 @@ def _search(stderr):
return m
def match(command, settings):
def match(command):
if 'EDITOR' not in os.environ:
return False
@@ -58,8 +59,8 @@ def match(command, settings):
@default_settings({'fixlinecmd': '{editor} {file} +{line}',
'fixcolcmd': None})
def get_new_command(command, settings):
'fixcolcmd': None})
def get_new_command(command):
m = _search(command.stderr) or _search(command.stdout)
# Note: there does not seem to be a standard for columns, so they are just
+2 -2
View File
@@ -4,13 +4,13 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('did not match any file(s) known to git.' in command.stderr
and "Did you forget to 'git add'?" in command.stderr)
@git_support
def get_new_command(command, settings):
def get_new_command(command):
missing_file = re.findall(
r"error: pathspec '([^']*)' "
r"did not match any file\(s\) known to git.", command.stderr)[0]
+2 -2
View File
@@ -3,11 +3,11 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('branch -d' in command.script
and 'If you are sure you want to delete it' in command.stderr)
@git_support
def get_new_command(command, settings):
def get_new_command(command):
return replace_argument(command.script, '-d', '-D')
+2 -2
View File
@@ -3,11 +3,11 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
# catches "git branch list" in place of "git branch"
return command.script.split()[1:] == 'branch list'.split()
@git_support
def get_new_command(command, settings):
def get_new_command(command):
return shells.and_('git branch --delete list', 'git branch')
+2 -2
View File
@@ -6,7 +6,7 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('did not match any file(s) known to git.' in command.stderr
and "Did you forget to 'git add'?" not in command.stderr)
@@ -25,7 +25,7 @@ def get_branches():
@git_support
def get_new_command(command, settings):
def get_new_command(command):
missing_file = re.findall(
r"error: pathspec '([^']*)' "
r"did not match any file\(s\) known to git.", command.stderr)[0]
+2 -2
View File
@@ -3,11 +3,11 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('diff' in command.script and
'--staged' not in command.script)
@git_support
def get_new_command(command, settings):
def get_new_command(command):
return replace_argument(command.script, 'diff', 'diff --staged')
+2 -2
View File
@@ -4,7 +4,7 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return (command.script.split()[1] == 'stash'
and 'usage:' in command.stderr)
@@ -21,7 +21,7 @@ stash_commands = (
@git_support
def get_new_command(command, settings):
def get_new_command(command):
stash_cmd = command.script.split()[2]
fixed = utils.get_closest(stash_cmd, stash_commands, fallback_to_first=False)
+2 -2
View File
@@ -4,13 +4,13 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return (" is not a git command. See 'git --help'." in command.stderr
and 'Did you mean' in command.stderr)
@git_support
def get_new_command(command, settings):
def get_new_command(command):
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
command.stderr)[0]
matched = get_all_matched_commands(command.stderr)
+2 -2
View File
@@ -3,13 +3,13 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('pull' in command.script
and 'set-upstream' in command.stderr)
@git_support
def get_new_command(command, settings):
def get_new_command(command):
line = command.stderr.split('\n')[-3].strip()
branch = line.split(' ')[-1]
set_upstream = line.replace('<remote>', 'origin')\
+2 -2
View File
@@ -3,11 +3,11 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('fatal: Not a git repository' in command.stderr
and "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." in command.stderr)
@git_support
def get_new_command(command, settings):
def get_new_command(command):
return replace_argument(command.script, 'pull', 'clone')
+2 -2
View File
@@ -2,11 +2,11 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('push' in command.script
and 'set-upstream' in command.stderr)
@git_support
def get_new_command(command, settings):
def get_new_command(command):
return command.stderr.split('\n')[-3].strip()
+2 -2
View File
@@ -3,7 +3,7 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('push' in command.script
and '! [rejected]' in command.stderr
and 'failed to push some refs to' in command.stderr
@@ -11,7 +11,7 @@ def match(command, settings):
@git_support
def get_new_command(command, settings):
def get_new_command(command):
return replace_argument(command.script, 'push', 'push --force')
+2 -2
View File
@@ -4,7 +4,7 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
return ('push' in command.script
and '! [rejected]' in command.stderr
and 'failed to push some refs to' in command.stderr
@@ -12,6 +12,6 @@ def match(command, settings):
@git_support
def get_new_command(command, settings):
def get_new_command(command):
return shells.and_(replace_argument(command.script, 'push', 'pull'),
command.script)
+2 -2
View File
@@ -3,13 +3,13 @@ from thefuck.specific.git import git_support
@git_support
def match(command, settings):
def match(command):
# catches "Please commit or stash them" and "Please, commit your changes or
# stash them before you can switch branches."
return 'or stash them' in command.stderr
@git_support
def get_new_command(command, settings):
def get_new_command(command):
formatme = shells.and_('git stash', '{}')
return formatme.format(command.script)
+2 -2
View File
@@ -7,10 +7,10 @@ from thefuck.utils import for_app
@for_app('go')
def match(command, settings):
def match(command):
return (command.script.startswith('go run ')
and not command.script.endswith('.go'))
def get_new_command(command, settings):
def get_new_command(command):
return command.script + '.go'
+2 -2
View File
@@ -2,9 +2,9 @@ from thefuck.utils import for_app
@for_app('grep')
def match(command, settings):
def match(command):
return 'is a directory' in command.stderr.lower()
def get_new_command(command, settings):
def get_new_command(command):
return 'grep -r {}'.format(command.script[5:])
+2 -2
View File
@@ -4,7 +4,7 @@ from thefuck.utils import replace_command, for_app
@for_app('gulp')
def match(command, script):
def match(command):
return 'is not in your gulpfile' in command.stdout
@@ -15,7 +15,7 @@ def get_gulp_tasks():
for line in proc.stdout.readlines()]
def get_new_command(command, script):
def get_new_command(command):
wrong_task = re.findall(r"Task '(\w+)' is not in your gulpfile",
command.stdout)[0]
return replace_command(command, wrong_task, get_gulp_tasks())
+2 -2
View File
@@ -3,11 +3,11 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command, settings):
def match(command):
return os.path.exists(command.script.split()[0]) \
and 'command not found' in command.stderr
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
return u'./{}'.format(command.script)
+2 -2
View File
@@ -3,7 +3,7 @@ from thefuck.utils import replace_command, for_app
@for_app('heroku')
def match(command, settings):
def match(command):
return 'is not a heroku command' in command.stderr and \
'Perhaps you meant' in command.stderr
@@ -14,6 +14,6 @@ def _get_suggests(stderr):
return re.findall(r'`([^`]+)`', line)
def get_new_command(command, settings):
def get_new_command(command):
wrong = re.findall(r'`(\w+)` is not a heroku command', command.stderr)[0]
return replace_command(command, wrong, _get_suggests(command.stderr))
+2 -2
View File
@@ -24,12 +24,12 @@ def _history_of_exists_without_current(command):
and line.split(' ')[0] in executables]
def match(command, settings):
def match(command):
return len(get_close_matches(command.script,
_history_of_exists_without_current(command)))
def get_new_command(command, settings):
def get_new_command(command):
return get_closest(command.script,
_history_of_exists_without_current(command))
+2 -2
View File
@@ -9,9 +9,9 @@ from thefuck.utils import for_app
@for_app('java')
def match(command, settings):
def match(command):
return command.script.endswith('.java')
def get_new_command(command, settings):
def get_new_command(command):
return command.script[:-5]
+2 -2
View File
@@ -10,9 +10,9 @@ from thefuck.utils import for_app
@for_app('javac')
def match(command, settings):
def match(command):
return not command.script.endswith('.java')
def get_new_command(command, settings):
def get_new_command(command):
return command.script + '.java'
+2 -2
View File
@@ -5,14 +5,14 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
@for_app('lein')
def match(command, settings):
def match(command):
return (command.script.startswith('lein')
and "is not a task. See 'lein help'" in command.stderr
and 'Did you mean this?' in command.stderr)
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
broken_cmd = re.findall(r"'([^']*)' is not a task",
command.stderr)[0]
new_cmds = get_all_matched_commands(command.stderr, 'Did you mean this?')
+2 -2
View File
@@ -2,11 +2,11 @@ from thefuck.utils import for_app
@for_app('ls')
def match(command, settings):
def match(command):
return 'ls -' not in command.script
def get_new_command(command, settings):
def get_new_command(command):
command = command.script.split(' ')
command[0] = 'ls -lah'
return ' '.join(command)
+2 -2
View File
@@ -1,8 +1,8 @@
def match(command, settings):
def match(command):
return command.script.strip().startswith('man ')
def get_new_command(command, settings):
def get_new_command(command):
if '3' in command.script:
return command.script.replace("3", "2")
if '2' in command.script:
+2 -2
View File
@@ -1,9 +1,9 @@
def match(command, settings):
def match(command):
return (command.script.startswith(u'man')
and u'command not found' in command.stderr.lower())
def get_new_command(command, settings):
def get_new_command(command):
return u'man {}'.format(command.script[3:])
priority = 2000
+2 -2
View File
@@ -13,14 +13,14 @@ def extract_possibilities(command):
@for_app('hg')
def match(command, settings):
def match(command):
return ('hg: unknown command' in command.stderr
and '(did you mean one of ' in command.stderr
or "hg: command '" in command.stderr
and "' is ambiguous:" in command.stderr)
def get_new_command(command, settings):
def get_new_command(command):
script = command.script.split(' ')
possibilities = extract_possibilities(command)
script[1] = get_closest(script[1], possibilities)
+2 -2
View File
@@ -3,11 +3,11 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command, settings):
def match(command):
return ('mkdir' in command.script
and 'No such file or directory' in command.stderr)
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
return re.sub('\\bmkdir (.*)', 'mkdir -p \\1', command.script)
+2 -2
View File
@@ -2,10 +2,10 @@ from thefuck.utils import for_app
@for_app('mvn')
def match(command, settings):
def match(command):
return 'No goals have been specified for this build' in command.stdout
def get_new_command(command, settings):
def get_new_command(command):
return [command.script + ' clean package',
command.script + ' clean install']
+2 -2
View File
@@ -14,13 +14,13 @@ def _getavailable_lifecycles(command):
@for_app('mvn')
def match(command, settings):
def match(command):
failed_lifecycle = _get_failed_lifecycle(command)
available_lifecycles = _getavailable_lifecycles(command)
return available_lifecycles and failed_lifecycle
def get_new_command(command, settings):
def get_new_command(command):
failed_lifecycle = _get_failed_lifecycle(command)
available_lifecycles = _getavailable_lifecycles(command)
if available_lifecycles and failed_lifecycle:
+2 -2
View File
@@ -4,14 +4,14 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command, settings):
def match(command):
return 'not found' in command.stderr and \
bool(get_close_matches(command.script.split(' ')[0],
get_all_executables()))
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
old_command = command.script.split(' ')[0]
new_cmds = get_close_matches(old_command, get_all_executables(), cutoff=0.1)
return [' '.join([new_command] + command.script.split(' ')[1:])
+2 -2
View File
@@ -10,7 +10,7 @@ patterns = (
)
def match(command, settings):
def match(command):
for pattern in patterns:
if re.search(pattern, command.stderr):
return True
@@ -18,7 +18,7 @@ def match(command, settings):
return False
def get_new_command(command, settings):
def get_new_command(command):
for pattern in patterns:
file = re.findall(pattern, command.stderr)
+2 -2
View File
@@ -9,7 +9,7 @@ from thefuck.utils import for_app
@for_app('open', 'xdg-open', 'gnome-open', 'kde-open')
def match(command, settings):
def match(command):
return ('.com' in command.script
or '.net' in command.script
or '.org' in command.script
@@ -22,5 +22,5 @@ def match(command, settings):
or 'www.' in command.script)
def get_new_command(command, settings):
def get_new_command(command):
return command.script.replace('open ', 'open http://')
+2 -2
View File
@@ -2,11 +2,11 @@ from thefuck.specific.archlinux import get_pkgfile, archlinux_env
from thefuck import shells
def match(command, settings):
def match(command):
return 'not found' in command.stderr and get_pkgfile(command.script)
def get_new_command(command, settings):
def get_new_command(command):
packages = get_pkgfile(command.script)
formatme = shells.and_('{} -S {}', '{}')
+2 -2
View File
@@ -10,12 +10,12 @@ from thefuck.utils import replace_command
from thefuck.specific.archlinux import get_pkgfile, archlinux_env
def match(command, settings):
def match(command):
return (command.script.startswith(('pacman', 'sudo pacman', 'yaourt'))
and 'error: target not found:' in command.stderr)
def get_new_command(command, settings):
def get_new_command(command):
pgr = command.script.split()[-1]
return replace_command(command, pgr, get_pkgfile(pgr))
+2 -2
View File
@@ -5,13 +5,13 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
@for_app('pip')
def match(command, settings):
def match(command):
return ('pip' in command.script and
'unknown command' in command.stderr and
'maybe you meant' in command.stderr)
def get_new_command(command, settings):
def get_new_command(command):
broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"',
command.stderr)[0]
new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.stderr)[0]
+2 -2
View File
@@ -5,7 +5,7 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command, settings):
def match(command):
toks = command.script.split()
return (len(toks) > 0
and toks[0].endswith('.py')
@@ -14,5 +14,5 @@ def match(command, settings):
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
return 'python ' + command.script
+2 -2
View File
@@ -7,9 +7,9 @@ from thefuck.utils import for_app
@for_app('python')
def match(command, settings):
def match(command):
return not command.script.endswith('.py')
def get_new_command(command, settings):
def get_new_command(command):
return command.script + '.py'
+2 -2
View File
@@ -4,9 +4,9 @@
# > git commit -m 'My Message"
def match(command, settings):
def match(command):
return '\'' in command.script and '\"' in command.script
def get_new_command(command, settings):
def get_new_command(command):
return command.script.replace('\'', '\"')
+2 -2
View File
@@ -3,13 +3,13 @@ from thefuck.specific.sudo import sudo_support
@sudo_support
def match(command, settings):
def match(command):
return ('rm' in command.script
and 'is a directory' in command.stderr.lower())
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
arguments = '-rf'
if 'hdfs' in command.script:
arguments = '-r'
+2 -2
View File
@@ -4,12 +4,12 @@ enabled_by_default = False
@sudo_support
def match(command, settings):
def match(command):
return ({'rm', '/'}.issubset(command.script.split())
and '--no-preserve-root' not in command.script
and '--no-preserve-root' in command.stderr)
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
return u'{} --no-preserve-root'.format(command.script)
+2 -2
View File
@@ -3,11 +3,11 @@ from thefuck.utils import quote, for_app
@for_app('sed')
def match(command, settings):
def match(command):
return "unterminated `s' command" in command.stderr
def get_new_command(command, settings):
def get_new_command(command):
script = shlex.split(command.script)
for (i, e) in enumerate(script):
+2 -2
View File
@@ -6,9 +6,9 @@ I often fuck up 'ls' and type 'sl'. No more!
"""
def match(command, settings):
def match(command):
return command.script == 'sl'
def get_new_command(command, settings):
def get_new_command(command):
return 'ls'
+3 -3
View File
@@ -5,7 +5,7 @@ commands = ('ssh', 'scp')
@for_app(*commands)
def match(command, settings):
def match(command):
if not command.script:
return False
if not command.script.startswith(commands):
@@ -20,11 +20,11 @@ def match(command, settings):
return any(re.findall(pattern, command.stderr) for pattern in patterns)
def get_new_command(command, settings):
def get_new_command(command):
return command.script
def side_effect(old_cmd, command, settings):
def side_effect(old_cmd, command):
offending_pattern = re.compile(
r'(?:Offending (?:key for IP|\S+ key)|Matching host key) in ([^:]+):(\d+)',
re.MULTILINE)
+2 -2
View File
@@ -19,7 +19,7 @@ patterns = ['permission denied',
'authentication is required']
def match(command, settings):
def match(command):
for pattern in patterns:
if pattern.lower() in command.stderr.lower()\
or pattern.lower() in command.stdout.lower():
@@ -27,7 +27,7 @@ def match(command, settings):
return False
def get_new_command(command, settings):
def get_new_command(command):
if '>' in command.script:
return u'sudo sh -c "{}"'.format(command.script.replace('"', '\\"'))
else:
+2 -2
View File
@@ -28,7 +28,7 @@ def _switch_command(command, layout):
return ''.join(_switch(ch, layout) for ch in command.script)
def match(command, settings):
def match(command):
if 'not found' not in command.stderr:
return False
matched_layout = _get_matched_layout(command)
@@ -36,6 +36,6 @@ def match(command, settings):
_switch_command(command, matched_layout) != thefuck_alias()
def get_new_command(command, settings):
def get_new_command(command):
matched_layout = _get_matched_layout(command)
return _switch_command(command, matched_layout)
+2 -2
View File
@@ -7,7 +7,7 @@ from thefuck.utils import for_app
@sudo_support
@for_app('systemctl')
def match(command, settings):
def match(command):
# Catches 'Unknown operation 'service'.' when executing systemctl with
# misordered arguments
cmd = command.script.split()
@@ -16,7 +16,7 @@ def match(command, settings):
@sudo_support
def get_new_command(command, settings):
def get_new_command(command):
cmd = command.script.split()
cmd[-1], cmd[-2] = cmd[-2], cmd[-1]
return ' '.join(cmd)
+2 -2
View File
@@ -1,8 +1,8 @@
def match(command, settings):
def match(command):
return command.script == 'test.py' and 'not found' in command.stderr
def get_new_command(command, settings):
def get_new_command(command):
return 'py.test'
+2 -2
View File
@@ -3,12 +3,12 @@ from thefuck.utils import replace_command, for_app
@for_app('tmux')
def match(command, settings):
def match(command):
return ('ambiguous command:' in command.stderr
and 'could be:' in command.stderr)
def get_new_command(command, settings):
def get_new_command(command):
cmd = re.match(r"ambiguous command: (.*), could be: (.*)",
command.stderr)
+2 -2
View File
@@ -3,10 +3,10 @@ from thefuck.utils import for_app
@for_app('tsuru')
def match(command, settings):
def match(command):
return ('not authenticated' in command.stderr
and 'session has expired' in command.stderr)
def get_new_command(command, settings):
def get_new_command(command):
return shells.and_('tsuru login', command.script)
+2 -2
View File
@@ -3,12 +3,12 @@ from thefuck.utils import get_all_matched_commands, replace_command, for_app
@for_app('tsuru')
def match(command, settings):
def match(command):
return (' is not a tsuru command. See "tsuru help".' in command.stderr
and '\nDid you mean?\n\t' in command.stderr)
def get_new_command(command, settings):
def get_new_command(command):
broken_cmd = re.findall(r'tsuru: "([^"]*)" is not a tsuru command',
command.stderr)[0]
return replace_command(command, broken_cmd,
+2 -2
View File
@@ -1,12 +1,12 @@
import re
from thefuck.utils import replace_command
def match(command, settings):
def match(command):
return (re.search(r"([^:]*): Unknown command.*", command.stderr) != None
and re.search(r"Did you mean ([^?]*)?", command.stderr) != None)
def get_new_command(command, settings):
def get_new_command(command):
broken_cmd = re.findall(r"([^:]*): Unknown command.*", command.stderr)[0]
matched = re.findall(r"Did you mean ([^?]*)?", command.stderr)
return replace_command(command, broken_cmd, matched)
+2 -2
View File
@@ -3,11 +3,11 @@ from thefuck.utils import for_app
@for_app('vagrant')
def match(command, settings):
def match(command):
return 'run `vagrant up`' in command.stderr.lower()
def get_new_command(command, settings):
def get_new_command(command):
cmds = command.script.split(' ')
machine = None
if len(cmds) >= 3:
+2 -2
View File
@@ -2,7 +2,7 @@
from six.moves.urllib.parse import urlparse
def match(command, settings):
def match(command):
"""
What the `whois` command returns depends on the 'Whois server' it contacted
and is not consistent through different servers. But there can be only two
@@ -22,7 +22,7 @@ def match(command, settings):
return 'whois ' in command.script.strip()
def get_new_command(command, settings):
def get_new_command(command):
url = command.script.split()[1]
if '/' in command.script:
+2 -2
View File
@@ -6,7 +6,7 @@ from ..utils import quote, is_app
@decorator
def git_support(fn, command, settings):
def git_support(fn, command):
"""Resolves git aliases and supports testing for both git and hub."""
# supports GitHub's `hub` command
# which is recommended to be used with `alias git=hub`
@@ -29,4 +29,4 @@ def git_support(fn, command, settings):
command = Command._replace(command, script=new_script)
return fn(command, settings)
return fn(command)
+3 -4
View File
@@ -4,15 +4,14 @@ from ..types import Command
@decorator
def sudo_support(fn, command, settings):
def sudo_support(fn, command):
"""Removes sudo before calling fn and adds it after."""
if not command.script.startswith('sudo '):
return fn(command, settings)
return fn(command)
result = fn(Command(command.script[5:],
command.stdout,
command.stderr),
settings)
command.stderr))
if result and isinstance(result, six.string_types):
return u'sudo {}'.format(result)
+29 -7
View File
@@ -1,6 +1,7 @@
from difflib import get_close_matches
from functools import wraps
import shelve
from warnings import warn
from decorator import decorator
from contextlib import closing
import tempfile
@@ -8,12 +9,12 @@ import tempfile
import os
import pickle
import re
from inspect import getargspec
from pathlib import Path
import pkg_resources
import six
from .types import Settings
from .conf import settings
DEVNULL = open(os.devnull, 'w')
@@ -70,11 +71,11 @@ def default_settings(params):
print(settings.apt)
"""
def _wrap_settings(fn, command, settings):
def _default_settings(fn, command):
for k, w in params.items():
settings.setdefault(k, w)
return fn(command, settings)
return decorator(_wrap_settings)
return fn(command)
return decorator(_default_settings)
def get_closest(word, possibilities, n=3, cutoff=0.6, fallback_to_first=True):
@@ -156,9 +157,9 @@ def is_app(command, *app_names):
def for_app(*app_names):
"""Specifies that matching script is for on of app names."""
def _for_app(fn, command, settings):
def _for_app(fn, command):
if is_app(command, *app_names):
return fn(command, settings)
return fn(command)
else:
return False
@@ -202,3 +203,24 @@ def cache(*depends_on):
return value
return _cache
cache.disabled = False
def compatibility_call(fn, *args):
"""Special call for compatibility with user-defined old-style rules
with `settings` param.
"""
fn_args_count = len(getargspec(fn).args)
if fn.__name__ in ('match', 'get_new_command') and fn_args_count == 2:
warn("Two arguments `{}` from rule `{}` is deprecated, please "
"remove `settings` argument and use "
"`from thefuck.conf import settings` instead."
.format(fn.__name__, fn.__module__))
args += (settings,)
if fn.__name__ == 'side_effect' and fn_args_count == 3:
warn("Three arguments `side_effect` from rule `{}` is deprecated, "
"please remove `settings` argument and use `from thefuck.conf "
"import settings` instead."
.format(fn.__name__, fn.__module__))
args += (settings,)
return fn(*args)