mirror of
https://github.com/nvbn/thefuck.git
synced 2025-11-10 11:56:08 +00:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20f8a4ad17 | ||
|
|
fdd6144f88 | ||
|
|
d1416a6c2a | ||
|
|
3df77b5bad | ||
|
|
da013c5c99 | ||
|
|
2a7cbef3b5 | ||
|
|
943613a194 | ||
|
|
5b97992d50 | ||
|
|
3f21d5fc3f | ||
|
|
d90e093fb7 | ||
|
|
8e18ff6eab | ||
|
|
54d82f9528 | ||
|
|
888756d519 | ||
|
|
d5b4bddc4c | ||
|
|
d09238a6e8 | ||
|
|
c6c3756caf | ||
|
|
275574beae | ||
|
|
de4b774134 | ||
|
|
3af5c80d29 | ||
|
|
bd5f5045aa | ||
|
|
798928b5ad | ||
|
|
82e2c89472 | ||
|
|
f2392349f7 | ||
|
|
478fa4cd09 | ||
|
|
273fc097bd | ||
|
|
00d0987cf5 | ||
|
|
3798c341d5 | ||
|
|
e1fe7ff7d0 | ||
|
|
e3edea05ed | ||
|
|
3606131502 | ||
|
|
8ed01fedbf | ||
|
|
ab8ac23749 |
@@ -71,8 +71,8 @@ REPL-y 0.3.1
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are scary to blindly run changed command, there's `require_confirmation`
|
If you are scared to blindly run changed command, there's `require_confirmation`
|
||||||
[settings](#Settings) option:
|
[settings](#settings) option:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
➜ apt-get install vim
|
➜ apt-get install vim
|
||||||
@@ -193,9 +193,7 @@ The Fuck has a few settings parameters, they can be changed in `~/.thefuck/setti
|
|||||||
|
|
||||||
* `rules` – list of enabled rules, by default all;
|
* `rules` – list of enabled rules, by default all;
|
||||||
* `require_confirmation` – require confirmation before running new command, by default `False`;
|
* `require_confirmation` – require confirmation before running new command, by default `False`;
|
||||||
* `wait_command` – max amount of time in seconds for getting previous command output;
|
* `wait_command` – max amount of time in seconds for getting previous command output.
|
||||||
* `command_not_found` – path to `command_not_found` binary,
|
|
||||||
by default `/usr/lib/command-not-found`.
|
|
||||||
|
|
||||||
## Developing
|
## Developing
|
||||||
|
|
||||||
|
|||||||
30
release.py
Executable file
30
release.py
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from subprocess import call
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
version = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_setup_py_lines():
|
||||||
|
global version
|
||||||
|
with open('setup.py', 'r') as sf:
|
||||||
|
current_setup = sf.readlines()
|
||||||
|
for line in current_setup:
|
||||||
|
if line.startswith('VERSION = '):
|
||||||
|
major, minor = re.findall(r"VERSION = '(\d+)\.(\d+)'", line)[0]
|
||||||
|
version = "{}.{}".format(major, int(minor) + 1)
|
||||||
|
yield "VERSION = '{}'\n".format(version)
|
||||||
|
else:
|
||||||
|
yield line
|
||||||
|
|
||||||
|
|
||||||
|
lines = list(get_new_setup_py_lines())
|
||||||
|
with open('setup.py', 'w') as sf:
|
||||||
|
sf.writelines(lines)
|
||||||
|
|
||||||
|
call('git commit -am "Bump to {}"'.format(version), shell=True)
|
||||||
|
call('git tag {}'.format(version), shell=True)
|
||||||
|
call('git push', shell=True)
|
||||||
|
call('git push --tags', shell=True)
|
||||||
|
call('python setup.py sdist upload', shell=True)
|
||||||
8
setup.py
8
setup.py
@@ -1,14 +1,18 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
|
||||||
|
VERSION = '1.24'
|
||||||
|
|
||||||
|
|
||||||
setup(name='thefuck',
|
setup(name='thefuck',
|
||||||
version=1.16,
|
version=VERSION,
|
||||||
description="Magnificent app which corrects your previous console command",
|
description="Magnificent app which corrects your previous console command",
|
||||||
author='Vladimir Iakovlev',
|
author='Vladimir Iakovlev',
|
||||||
author_email='nvbn.rm@gmail.com',
|
author_email='nvbn.rm@gmail.com',
|
||||||
url='https://github.com/nvbn/thefuck',
|
url='https://github.com/nvbn/thefuck',
|
||||||
license='MIT',
|
license='MIT',
|
||||||
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
|
packages=find_packages(exclude=['ez_setup', 'examples',
|
||||||
|
'tests', 'release']),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
install_requires=['pathlib', 'psutil'],
|
install_requires=['pathlib', 'psutil'],
|
||||||
|
|||||||
12
tests/rules/test_cd_parent.py
Normal file
12
tests/rules/test_cd_parent.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from thefuck.main import Command
|
||||||
|
from thefuck.rules.cd_parent import match, get_new_command
|
||||||
|
|
||||||
|
|
||||||
|
def test_match():
|
||||||
|
assert match(Command('cd..', '', 'cd..: command not found'), None)
|
||||||
|
assert not match(Command('', '', ''), None)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_new_command():
|
||||||
|
assert get_new_command(
|
||||||
|
Command('cd..', '', ''), None) == 'cd ..'
|
||||||
@@ -1,62 +1,19 @@
|
|||||||
from subprocess import PIPE
|
|
||||||
from mock import patch, Mock
|
from mock import patch, Mock
|
||||||
import pytest
|
|
||||||
from thefuck.rules.no_command import match, get_new_command
|
from thefuck.rules.no_command import match, get_new_command
|
||||||
from thefuck.main import Command
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
def test_match():
|
||||||
def command_found():
|
with patch('thefuck.rules.no_command._get_all_bins',
|
||||||
return b'''No command 'aptget' found, did you mean:
|
return_value=['vim', 'apt-get']):
|
||||||
Command 'apt-get' from package 'apt' (main)
|
assert match(Mock(stderr='vom: not found', script='vom file.py'), None)
|
||||||
aptget: command not found
|
assert not match(Mock(stderr='qweqwe: not found', script='qweqwe'), None)
|
||||||
'''
|
assert not match(Mock(stderr='some text', script='vom file.py'), None)
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def command_not_found():
|
|
||||||
return b'''No command 'vom' found, but there are 19 similar ones
|
|
||||||
vom: command not found
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
def test_get_new_command():
|
||||||
def bins_exists(request):
|
with patch('thefuck.rules.no_command._get_all_bins',
|
||||||
p = patch('thefuck.rules.no_command.which',
|
return_value=['vim', 'apt-get']):
|
||||||
return_value=True)
|
assert get_new_command(
|
||||||
p.start()
|
Mock(stderr='vom: not found',
|
||||||
request.addfinalizer(p.stop)
|
script='vom file.py'),
|
||||||
|
None) == 'vim file.py'
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def settings():
|
|
||||||
class _Settings(object):
|
|
||||||
pass
|
|
||||||
return _Settings
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('bins_exists')
|
|
||||||
def test_match(command_found, command_not_found, settings):
|
|
||||||
with patch('thefuck.rules.no_command.Popen') as Popen:
|
|
||||||
Popen.return_value.stderr.read.return_value = command_found
|
|
||||||
assert match(Command('aptget install vim', '', ''), settings)
|
|
||||||
Popen.assert_called_once_with('/usr/lib/command-not-found aptget',
|
|
||||||
shell=True, stderr=PIPE)
|
|
||||||
Popen.return_value.stderr.read.return_value = command_not_found
|
|
||||||
assert not match(Command('ls', '', ''), settings)
|
|
||||||
|
|
||||||
with patch('thefuck.rules.no_command.Popen') as Popen:
|
|
||||||
Popen.return_value.stderr.read.return_value = command_found
|
|
||||||
assert match(Command('sudo aptget install vim', '', ''),
|
|
||||||
Mock(command_not_found='test'))
|
|
||||||
Popen.assert_called_once_with('test aptget',
|
|
||||||
shell=True, stderr=PIPE)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('bins_exists')
|
|
||||||
def test_get_new_command(command_found):
|
|
||||||
with patch('thefuck.rules.no_command._get_output',
|
|
||||||
return_value=command_found.decode()):
|
|
||||||
assert get_new_command(Command('aptget install vim', '', ''), settings)\
|
|
||||||
== 'apt-get install vim'
|
|
||||||
assert get_new_command(Command('sudo aptget install vim', '', ''), settings) \
|
|
||||||
== 'sudo apt-get install vim'
|
|
||||||
|
|||||||
69
tests/rules/test_ssh_known_host.py
Normal file
69
tests/rules/test_ssh_known_host.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
from mock import Mock
|
||||||
|
from thefuck.main import Command
|
||||||
|
from thefuck.rules.ssh_known_hosts import match, get_new_command, remove_offending_keys
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def ssh_error(tmpdir):
|
||||||
|
path = os.path.join(str(tmpdir), 'known_hosts')
|
||||||
|
|
||||||
|
def reset(path):
|
||||||
|
with open(path, 'w') as fh:
|
||||||
|
lines = [
|
||||||
|
'123.234.567.890 asdjkasjdakjsd\n'
|
||||||
|
'98.765.432.321 ejioweojwejrosj\n'
|
||||||
|
'111.222.333.444 qwepoiwqepoiss\n'
|
||||||
|
]
|
||||||
|
fh.writelines(lines)
|
||||||
|
|
||||||
|
def known_hosts(path):
|
||||||
|
with open(path, 'r') as fh:
|
||||||
|
return fh.readlines()
|
||||||
|
|
||||||
|
reset(path)
|
||||||
|
|
||||||
|
errormsg = u"""@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
|
||||||
|
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
|
||||||
|
It is also possible that a host key has just been changed.
|
||||||
|
The fingerprint for the RSA key sent by the remote host is
|
||||||
|
b6:cb:07:34:c0:a0:94:d3:0d:69:83:31:f4:c5:20:9b.
|
||||||
|
Please contact your system administrator.
|
||||||
|
Add correct host key in {0} to get rid of this message.
|
||||||
|
Offending RSA key in {0}:2
|
||||||
|
RSA host key for {1} has changed and you have requested strict checking.
|
||||||
|
Host key verification failed.""".format(path, '98.765.432.321')
|
||||||
|
|
||||||
|
return errormsg, path, reset, known_hosts
|
||||||
|
|
||||||
|
|
||||||
|
def test_match(ssh_error):
|
||||||
|
errormsg, _, _, _ = ssh_error
|
||||||
|
assert match(Command('ssh', '', errormsg), None)
|
||||||
|
assert match(Command('ssh', '', errormsg), None)
|
||||||
|
assert match(Command('scp something something', '', errormsg), None)
|
||||||
|
assert match(Command('scp something something', '', errormsg), None)
|
||||||
|
assert not match(Command('', '', errormsg), None)
|
||||||
|
assert not match(Command('notssh', '', errormsg), None)
|
||||||
|
assert not match(Command('ssh', '', ''), None)
|
||||||
|
|
||||||
|
|
||||||
|
def test_remove_offending_keys(ssh_error):
|
||||||
|
errormsg, path, reset, known_hosts = ssh_error
|
||||||
|
command = Command('ssh user@host', '', errormsg)
|
||||||
|
remove_offending_keys(command, None)
|
||||||
|
expected = ['123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n']
|
||||||
|
assert known_hosts(path) == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_new_command(ssh_error, monkeypatch):
|
||||||
|
errormsg, _, _, _ = ssh_error
|
||||||
|
|
||||||
|
method = Mock()
|
||||||
|
monkeypatch.setattr('thefuck.rules.ssh_known_hosts.remove_offending_keys', method)
|
||||||
|
assert get_new_command(Command('ssh user@host', '', errormsg), None) == 'ssh user@host'
|
||||||
|
assert method.call_count
|
||||||
@@ -24,7 +24,7 @@ def test_load_rule():
|
|||||||
return_value=Mock(
|
return_value=Mock(
|
||||||
match=match,
|
match=match,
|
||||||
get_new_command=get_new_command)) as load_source:
|
get_new_command=get_new_command)) as load_source:
|
||||||
assert main.load_rule(Path('/rules/bash.py')) == main.Rule(match, get_new_command)
|
assert main.load_rule(Path('/rules/bash.py')) == main.Rule('bash', match, get_new_command)
|
||||||
load_source.assert_called_once_with('bash', '/rules/bash.py')
|
load_source.assert_called_once_with('bash', '/rules/bash.py')
|
||||||
|
|
||||||
|
|
||||||
@@ -35,14 +35,14 @@ def test_get_rules():
|
|||||||
glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
|
glob.return_value = [PosixPath('bash.py'), PosixPath('lisp.py')]
|
||||||
assert main.get_rules(
|
assert main.get_rules(
|
||||||
Path('~'),
|
Path('~'),
|
||||||
Mock(rules=None)) == [main.Rule('bash', 'bash'),
|
Mock(rules=None)) == [main.Rule('bash', 'bash', 'bash'),
|
||||||
main.Rule('lisp', 'lisp'),
|
main.Rule('lisp', 'lisp', 'lisp'),
|
||||||
main.Rule('bash', 'bash'),
|
main.Rule('bash', 'bash', 'bash'),
|
||||||
main.Rule('lisp', 'lisp')]
|
main.Rule('lisp', 'lisp', 'lisp')]
|
||||||
assert main.get_rules(
|
assert main.get_rules(
|
||||||
Path('~'),
|
Path('~'),
|
||||||
Mock(rules=['bash'])) == [main.Rule('bash', 'bash'),
|
Mock(rules=['bash'])) == [main.Rule('bash', 'bash', 'bash'),
|
||||||
main.Rule('bash', 'bash')]
|
main.Rule('bash', 'bash', 'bash')]
|
||||||
|
|
||||||
|
|
||||||
def test_get_command():
|
def test_get_command():
|
||||||
@@ -53,32 +53,36 @@ def test_get_command():
|
|||||||
return_value=True):
|
return_value=True):
|
||||||
Popen.return_value.stdout.read.return_value = b'stdout'
|
Popen.return_value.stdout.read.return_value = b'stdout'
|
||||||
Popen.return_value.stderr.read.return_value = b'stderr'
|
Popen.return_value.stderr.read.return_value = b'stderr'
|
||||||
assert main.get_command(Mock(), [b'thefuck', b'apt-get',
|
assert main.get_command(Mock(), ['thefuck', 'apt-get',
|
||||||
b'search', b'vim']) \
|
'search', 'vim']) \
|
||||||
== main.Command('apt-get search vim', 'stdout', 'stderr')
|
== main.Command('apt-get search vim', 'stdout', 'stderr')
|
||||||
Popen.assert_called_once_with('apt-get search vim',
|
Popen.assert_called_once_with('apt-get search vim',
|
||||||
shell=True,
|
shell=True,
|
||||||
stdout=PIPE,
|
stdout=PIPE,
|
||||||
stderr=PIPE,
|
stderr=PIPE,
|
||||||
env={'LANG': 'C'})
|
env={'LANG': 'C'})
|
||||||
|
assert main.get_command(Mock(), ['']) is None
|
||||||
|
|
||||||
|
|
||||||
def test_get_matched_rule():
|
def test_get_matched_rule(capsys):
|
||||||
rules = [main.Rule(lambda x, _: x.script == 'cd ..', None),
|
rules = [main.Rule('', lambda x, _: x.script == 'cd ..', None),
|
||||||
main.Rule(lambda *_: False, None)]
|
main.Rule('', lambda *_: False, None),
|
||||||
|
main.Rule('rule', Mock(side_effect=OSError('Denied')), None)]
|
||||||
assert main.get_matched_rule(main.Command('ls', '', ''),
|
assert main.get_matched_rule(main.Command('ls', '', ''),
|
||||||
rules, None) is None
|
rules, None) is None
|
||||||
assert main.get_matched_rule(main.Command('cd ..', '', ''),
|
assert main.get_matched_rule(main.Command('cd ..', '', ''),
|
||||||
rules, None) == rules[0]
|
rules, None) == rules[0]
|
||||||
|
assert capsys.readouterr()[1].split('\n')[0]\
|
||||||
|
== '[WARN] rule: Traceback (most recent call last):'
|
||||||
|
|
||||||
|
|
||||||
def test_run_rule(capsys):
|
def test_run_rule(capsys):
|
||||||
with patch('thefuck.main.confirm', return_value=True):
|
with patch('thefuck.main.confirm', return_value=True):
|
||||||
main.run_rule(main.Rule(None, lambda *_: 'new-command'),
|
main.run_rule(main.Rule('', None, lambda *_: 'new-command'),
|
||||||
None, None)
|
None, None)
|
||||||
assert capsys.readouterr() == ('new-command\n', '')
|
assert capsys.readouterr() == ('new-command\n', '')
|
||||||
with patch('thefuck.main.confirm', return_value=False):
|
with patch('thefuck.main.confirm', return_value=False):
|
||||||
main.run_rule(main.Rule(None, lambda *_: 'new-command'),
|
main.run_rule(main.Rule('', None, lambda *_: 'new-command'),
|
||||||
None, None)
|
None, None)
|
||||||
assert capsys.readouterr() == ('', '')
|
assert capsys.readouterr() == ('', '')
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ from os.path import expanduser
|
|||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from traceback import format_exception
|
||||||
from psutil import Process, TimeoutExpired
|
from psutil import Process, TimeoutExpired
|
||||||
|
|
||||||
|
|
||||||
Command = namedtuple('Command', ('script', 'stdout', 'stderr'))
|
Command = namedtuple('Command', ('script', 'stdout', 'stderr'))
|
||||||
Rule = namedtuple('Rule', ('match', 'get_new_command'))
|
Rule = namedtuple('Rule', ('name', 'match', 'get_new_command'))
|
||||||
|
|
||||||
|
|
||||||
def setup_user_dir():
|
def setup_user_dir():
|
||||||
@@ -43,7 +44,8 @@ def is_rule_enabled(settings, rule):
|
|||||||
def load_rule(rule):
|
def load_rule(rule):
|
||||||
"""Imports rule module and returns it."""
|
"""Imports rule module and returns it."""
|
||||||
rule_module = load_source(rule.name[:-3], str(rule))
|
rule_module = load_source(rule.name[:-3], str(rule))
|
||||||
return Rule(rule_module.match, rule_module.get_new_command)
|
return Rule(rule.name[:-3], rule_module.match,
|
||||||
|
rule_module.get_new_command)
|
||||||
|
|
||||||
|
|
||||||
def get_rules(user_dir, settings):
|
def get_rules(user_dir, settings):
|
||||||
@@ -76,7 +78,14 @@ def wait_output(settings, popen):
|
|||||||
|
|
||||||
def get_command(settings, args):
|
def get_command(settings, args):
|
||||||
"""Creates command from `args` and executes it."""
|
"""Creates command from `args` and executes it."""
|
||||||
script = ' '.join(arg.decode('utf-8') for arg in args[1:])
|
if sys.version_info[0] < 3:
|
||||||
|
script = ' '.join(arg.decode('utf-8') for arg in args[1:])
|
||||||
|
else:
|
||||||
|
script = ' '.join(args[1:])
|
||||||
|
|
||||||
|
if not script:
|
||||||
|
return
|
||||||
|
|
||||||
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE,
|
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE,
|
||||||
env=dict(os.environ, LANG='C'))
|
env=dict(os.environ, LANG='C'))
|
||||||
if wait_output(settings, result):
|
if wait_output(settings, result):
|
||||||
@@ -87,8 +96,12 @@ def get_command(settings, args):
|
|||||||
def get_matched_rule(command, rules, settings):
|
def get_matched_rule(command, rules, settings):
|
||||||
"""Returns first matched rule for command."""
|
"""Returns first matched rule for command."""
|
||||||
for rule in rules:
|
for rule in rules:
|
||||||
if rule.match(command, settings):
|
try:
|
||||||
return rule
|
if rule.match(command, settings):
|
||||||
|
return rule
|
||||||
|
except Exception:
|
||||||
|
sys.stderr.write(u'[WARN] {}: {}---------------------\n\n'.format(
|
||||||
|
rule.name, ''.join(format_exception(*sys.exc_info()))))
|
||||||
|
|
||||||
|
|
||||||
def confirm(new_command, settings):
|
def confirm(new_command, settings):
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
from subprocess import Popen, PIPE
|
from difflib import get_close_matches
|
||||||
import re
|
import os
|
||||||
from thefuck.utils import which, wrap_settings
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
local_settings = {'command_not_found': '/usr/lib/command-not-found'}
|
def _safe(fn, fallback):
|
||||||
|
try:
|
||||||
|
return fn()
|
||||||
|
except OSError:
|
||||||
|
return fallback
|
||||||
|
|
||||||
|
|
||||||
def _get_output(command, settings):
|
def _get_all_bins():
|
||||||
name = command.script.split(' ')[command.script.startswith('sudo')]
|
return [exe.name
|
||||||
check_script = u'{} {}'.format(settings.command_not_found, name)
|
for path in os.environ.get('PATH', '').split(':')
|
||||||
result = Popen(check_script, shell=True, stderr=PIPE)
|
for exe in _safe(lambda: list(Path(path).iterdir()), [])
|
||||||
return result.stderr.read().decode('utf-8')
|
if not _safe(exe.is_dir, True)]
|
||||||
|
|
||||||
|
|
||||||
@wrap_settings(local_settings)
|
|
||||||
def match(command, settings):
|
def match(command, settings):
|
||||||
if which(settings.command_not_found):
|
return 'not found' in command.stderr and \
|
||||||
output = _get_output(command, settings)
|
bool(get_close_matches(command.script.split(' ')[0],
|
||||||
return "No command" in output and "from package" in output
|
_get_all_bins()))
|
||||||
|
|
||||||
|
|
||||||
@wrap_settings(local_settings)
|
|
||||||
def get_new_command(command, settings):
|
def get_new_command(command, settings):
|
||||||
output = _get_output(command, settings)
|
old_command = command.script.split(' ')[0]
|
||||||
broken_name = re.findall(r"No command '([^']*)' found",
|
new_command = get_close_matches(old_command,
|
||||||
output)[0]
|
_get_all_bins())[0]
|
||||||
fixed_name = re.findall(r"Command '([^']*)' from package",
|
return ' '.join([new_command] + command.script.split(' ')[1:])
|
||||||
output)[0]
|
|
||||||
return command.script.replace(broken_name, fixed_name, 1)
|
|
||||||
|
|||||||
37
thefuck/rules/ssh_known_hosts.py
Normal file
37
thefuck/rules/ssh_known_hosts.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
patterns = [
|
||||||
|
r'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!',
|
||||||
|
r'WARNING: POSSIBLE DNS SPOOFING DETECTED!',
|
||||||
|
r"Warning: the \S+ host key for '([^']+)' differs from the key for the IP address '([^']+)'",
|
||||||
|
]
|
||||||
|
offending_pattern = re.compile(
|
||||||
|
r'(?:Offending (?:key for IP|\S+ key)|Matching host key) in ([^:]+):(\d+)',
|
||||||
|
re.MULTILINE)
|
||||||
|
|
||||||
|
commands = ['ssh', 'scp']
|
||||||
|
|
||||||
|
|
||||||
|
def match(command, settings):
|
||||||
|
if not command.script:
|
||||||
|
return False
|
||||||
|
if not command.script.split()[0] in commands:
|
||||||
|
return False
|
||||||
|
if not any([re.findall(pattern, command.stderr) for pattern in patterns]):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def remove_offending_keys(command, settings):
|
||||||
|
offending = offending_pattern.findall(command.stderr)
|
||||||
|
for filepath, lineno in offending:
|
||||||
|
with open(filepath, 'r') as fh:
|
||||||
|
lines = fh.readlines()
|
||||||
|
del lines[int(lineno) - 1]
|
||||||
|
with open(filepath, 'w') as fh:
|
||||||
|
fh.writelines(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_command(command, settings):
|
||||||
|
remove_offending_keys(command, settings)
|
||||||
|
return command.script
|
||||||
@@ -3,7 +3,9 @@ patterns = ['permission denied',
|
|||||||
'pkg: Insufficient privileges',
|
'pkg: Insufficient privileges',
|
||||||
'you cannot perform this operation unless you are root',
|
'you cannot perform this operation unless you are root',
|
||||||
'non-root users cannot',
|
'non-root users cannot',
|
||||||
'Operation not permitted']
|
'Operation not permitted',
|
||||||
|
'root privilege',
|
||||||
|
'This command has to be run under the root user.']
|
||||||
|
|
||||||
|
|
||||||
def match(command, settings):
|
def match(command, settings):
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?'''
|
target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?'''
|
||||||
|
|
||||||
source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''']
|
source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''',
|
||||||
|
u'''ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپو./ًٌٍَُِّْ][}{ؤئيإأآة»«:؛كٓژٰٔء><؟''']
|
||||||
|
|
||||||
|
|
||||||
def _get_matched_layout(command):
|
def _get_matched_layout(command):
|
||||||
|
|||||||
Reference in New Issue
Block a user