1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-11-09 03:22:06 +00:00

Compare commits

...

10 Commits
1.17 ... 1.21

Author SHA1 Message Date
nvbn
798928b5ad #71 Don't fail on non-exists dir in $PATH 2015-04-21 08:45:45 +02:00
nvbn
82e2c89472 Fix version number 2015-04-21 08:40:17 +02:00
nvbn
f2392349f7 #71 Handle OSError more gratefully 2015-04-21 08:38:52 +02:00
nvbn
478fa4cd09 #71 Not fail on os error 2015-04-21 08:30:48 +02:00
Vladimir Iakovlev
273fc097bd Update switch_lang.py 2015-04-21 07:16:36 +02:00
Vladimir Iakovlev
00d0987cf5 Merge pull request #70 from fzerorubigd/master
add persian language to switch lang rule
2015-04-21 07:15:53 +02:00
fzerorubigd
3798c341d5 add persian language to switch lang rule
refs #28
2015-04-21 09:42:13 +04:30
nvbn
e1fe7ff7d0 Bump version 2015-04-21 06:56:26 +02:00
nvbn
e3edea05ed #24 Make no_command crossplatform 2015-04-21 06:55:47 +02:00
nvbn
3606131502 Fix tests 2015-04-21 06:36:51 +02:00
6 changed files with 39 additions and 83 deletions

View File

@@ -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

View File

@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(name='thefuck', setup(name='thefuck',
version=1.17, version="1.21",
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',

View File

@@ -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'

View File

@@ -53,8 +53,8 @@ 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,

View File

@@ -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['PATH'].split(':')
result = Popen(check_script, shell=True, stderr=PIPE) for exe in _safe(lambda: 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)

View File

@@ -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):