Merge branch 'master' of github.com:nvbn/thefuck
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
from thefuck.utils import is_app, get_closest, replace_argument
|
||||
|
||||
|
||||
_ADB_COMMANDS = (
|
||||
'backup',
|
||||
'bugreport',
|
||||
'connect',
|
||||
'devices',
|
||||
'disable-verity',
|
||||
'disconnect',
|
||||
'enable-verity',
|
||||
'emu',
|
||||
'forward',
|
||||
'get-devpath',
|
||||
'get-serialno',
|
||||
'get-state',
|
||||
'install',
|
||||
'install-multiple',
|
||||
'jdwp',
|
||||
'keygen',
|
||||
'kill-server',
|
||||
'logcat',
|
||||
'pull',
|
||||
'push',
|
||||
'reboot',
|
||||
'reconnect',
|
||||
'restore',
|
||||
'reverse',
|
||||
'root',
|
||||
'run-as',
|
||||
'shell',
|
||||
'sideload',
|
||||
'start-server',
|
||||
'sync',
|
||||
'tcpip',
|
||||
'uninstall',
|
||||
'unroot',
|
||||
'usb',
|
||||
'wait-for',
|
||||
)
|
||||
|
||||
|
||||
def match(command):
|
||||
return (is_app(command, 'adb')
|
||||
and command.output.startswith('Android Debug Bridge version'))
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
for idx, arg in enumerate(command.script_parts[1:]):
|
||||
# allowed params to ADB are a/d/e/s/H/P/L where s, H, P and L take additional args
|
||||
# for example 'adb -s 111 logcat' or 'adb -e logcat'
|
||||
if not arg[0] == '-' and not command.script_parts[idx] in ('-s', '-H', '-P', '-L'):
|
||||
adb_cmd = get_closest(arg, _ADB_COMMANDS)
|
||||
return replace_argument(command.script, arg, adb_cmd)
|
||||
@@ -11,5 +11,6 @@ def match(command):
|
||||
return "Run 'apt list --upgradable' to see them." in command.output
|
||||
|
||||
|
||||
@sudo_support
|
||||
def get_new_command(command):
|
||||
return 'apt list --upgradable'
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
from thefuck.specific.apt import apt_available
|
||||
from thefuck.specific.sudo import sudo_support
|
||||
from thefuck.utils import for_app
|
||||
|
||||
enabled_by_default = apt_available
|
||||
|
||||
|
||||
@sudo_support
|
||||
@for_app('apt')
|
||||
def match(command):
|
||||
return command.script == "apt list --upgradable" and len(command.output.strip().split('\n')) > 1
|
||||
|
||||
|
||||
@sudo_support
|
||||
def get_new_command(command):
|
||||
return 'apt upgrade'
|
||||
@@ -7,14 +7,15 @@ from thefuck.utils import eager
|
||||
@git_support
|
||||
def match(command):
|
||||
return ("fatal: A branch named '" in command.output
|
||||
and " already exists." in command.output)
|
||||
and "' already exists." in command.output)
|
||||
|
||||
|
||||
@git_support
|
||||
@eager
|
||||
def get_new_command(command):
|
||||
branch_name = re.findall(
|
||||
r"fatal: A branch named '([^']*)' already exists.", command.output)[0]
|
||||
r"fatal: A branch named '(.+)' already exists.", command.output)[0]
|
||||
branch_name = branch_name.replace("'", r"\'")
|
||||
new_command_templates = [['git branch -d {0}', 'git branch {0}'],
|
||||
['git branch -d {0}', 'git checkout -b {0}'],
|
||||
['git branch -D {0}', 'git branch {0}'],
|
||||
|
||||
@@ -34,6 +34,8 @@ def get_new_command(command):
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
from thefuck.specific.git import git_support
|
||||
|
||||
|
||||
@git_support
|
||||
def match(command):
|
||||
return ('commit' in command.script_parts)
|
||||
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
return 'git commit --amend'
|
||||
@@ -0,0 +1,18 @@
|
||||
import re
|
||||
from thefuck.utils import replace_argument
|
||||
from thefuck.specific.git import git_support
|
||||
|
||||
|
||||
@git_support
|
||||
def match(command):
|
||||
return ('merge' in command.script
|
||||
and ' - not something we can merge' in command.output
|
||||
and 'Did you mean this?' in command.output)
|
||||
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
unknown_branch = re.findall(r'merge: (.+) - not something we can merge', command.output)[0]
|
||||
remote_branch = re.findall(r'Did you mean this\?\n\t([^\n]+)', command.output)[0]
|
||||
|
||||
return replace_argument(command.script, unknown_branch, remote_branch)
|
||||
@@ -0,0 +1,12 @@
|
||||
from thefuck.specific.git import git_support
|
||||
|
||||
|
||||
@git_support
|
||||
def match(command):
|
||||
return ('merge' in command.script
|
||||
and 'fatal: refusing to merge unrelated histories' in command.output)
|
||||
|
||||
|
||||
@git_support
|
||||
def get_new_command(command):
|
||||
return command.script + ' --allow-unrelated-histories'
|
||||
@@ -5,8 +5,8 @@ from thefuck.specific.git import git_support
|
||||
|
||||
@git_support
|
||||
def match(command):
|
||||
return ('push' in command.script
|
||||
and 'set-upstream' in command.output)
|
||||
return ('push' in command.script_parts
|
||||
and 'git push --set-upstream' in command.output)
|
||||
|
||||
|
||||
def _get_upstream_option_index(command_parts):
|
||||
@@ -32,7 +32,13 @@ def get_new_command(command):
|
||||
# In case of `git push -u` we don't have next argument:
|
||||
if len(command_parts) > upstream_option_index:
|
||||
command_parts.pop(upstream_option_index)
|
||||
else:
|
||||
# the only non-qualified permitted options are the repository and refspec; git's
|
||||
# suggestion include them, so they won't be lost, but would be duplicated otherwise.
|
||||
push_idx = command_parts.index('push') + 1
|
||||
while len(command_parts) > push_idx and command_parts[len(command_parts) - 1][0] != '-':
|
||||
command_parts.pop(len(command_parts) - 1)
|
||||
|
||||
arguments = re.findall(r'git push (.*)', command.output)[0].strip()
|
||||
arguments = re.findall(r'git push (.*)', command.output)[0].replace("'", r"\'").strip()
|
||||
return replace_argument(" ".join(command_parts), 'push',
|
||||
'push {}'.format(arguments))
|
||||
|
||||
@@ -5,7 +5,8 @@ target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVB
|
||||
|
||||
source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''',
|
||||
u'''ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپو./ًٌٍَُِّْ][}{ؤئيإأآة»«:؛كٓژٰٔء><؟''',
|
||||
u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?''']
|
||||
u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?''',
|
||||
u'''/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''']
|
||||
|
||||
|
||||
@memoize
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
patterns = ['you cannot perform this operation as root']
|
||||
|
||||
|
||||
def match(command):
|
||||
if command.script_parts and command.script_parts[0] != 'sudo':
|
||||
return False
|
||||
|
||||
for pattern in patterns:
|
||||
if pattern in command.output.lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return ' '.join(command.script_parts[1:])
|
||||
+21
-4
@@ -10,12 +10,24 @@ from .generic import Generic
|
||||
|
||||
|
||||
@cache('~/.config/fish/config.fish', '~/.config/fish/functions')
|
||||
def _get_aliases(overridden):
|
||||
def _get_functions(overridden):
|
||||
proc = Popen(['fish', '-ic', 'functions'], stdout=PIPE, stderr=DEVNULL)
|
||||
functions = proc.stdout.read().decode('utf-8').strip().split('\n')
|
||||
return {func: func for func in functions if func not in overridden}
|
||||
|
||||
|
||||
@cache('~/.config/fish/config.fish')
|
||||
def _get_aliases(overridden):
|
||||
aliases = {}
|
||||
proc = Popen(['fish', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
|
||||
alias_out = proc.stdout.read().decode('utf-8').strip().split('\n')
|
||||
for alias in alias_out:
|
||||
name, value = alias.replace('alias ', '', 1).split(' ', 1)
|
||||
if name not in overridden:
|
||||
aliases[name] = value
|
||||
return aliases
|
||||
|
||||
|
||||
class Fish(Generic):
|
||||
def _get_overridden_aliases(self):
|
||||
overridden = os.environ.get('THEFUCK_OVERRIDDEN_ALIASES',
|
||||
@@ -35,7 +47,7 @@ class Fish(Generic):
|
||||
# It is VERY important to have the variables declared WITHIN the alias
|
||||
return ('function {0} -d "Correct your previous console command"\n'
|
||||
' set -l fucked_up_command $history[1]\n'
|
||||
' env TF_ALIAS={0} PYTHONIOENCODING=utf-8'
|
||||
' env TF_SHELL=fish TF_ALIAS={0} PYTHONIOENCODING=utf-8'
|
||||
' thefuck $fucked_up_command | read -l unfucked_command\n'
|
||||
' if [ "$unfucked_command" != "" ]\n'
|
||||
' eval $unfucked_command\n{1}'
|
||||
@@ -44,12 +56,17 @@ class Fish(Generic):
|
||||
|
||||
def get_aliases(self):
|
||||
overridden = self._get_overridden_aliases()
|
||||
return _get_aliases(overridden)
|
||||
functions = _get_functions(overridden)
|
||||
raw_aliases = _get_aliases(overridden)
|
||||
functions.update(raw_aliases)
|
||||
return functions
|
||||
|
||||
def _expand_aliases(self, command_script):
|
||||
aliases = self.get_aliases()
|
||||
binary = command_script.split(' ')[0]
|
||||
if binary in aliases:
|
||||
if binary in aliases and aliases[binary] != binary:
|
||||
return command_script.replace(binary, aliases[binary], 1)
|
||||
elif binary in aliases:
|
||||
return u'fish -ic "{}"'.format(command_script.replace('"', r'\"'))
|
||||
else:
|
||||
return command_script
|
||||
|
||||
@@ -7,7 +7,7 @@ from .generic import Generic
|
||||
|
||||
class Tcsh(Generic):
|
||||
def app_alias(self, alias_name):
|
||||
return ("alias {0} 'setenv TF_ALIAS {0} && "
|
||||
return ("alias {0} 'setenv TF_SHELL tcsh && setenv TF_ALIAS {0} && "
|
||||
"set fucked_cmd=`history -h 2 | head -n 1` && "
|
||||
"eval `thefuck ${{fucked_cmd}}`'").format(alias_name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user