diff --git a/README.md b/README.md index 6bfafd69..60efa2aa 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,8 @@ using matched rule and run it. Rules enabled by default: * `no_command` – fixes wrong console commands, for example `vom/vim`; * `python_command` – prepends `python` when you trying to run not executable/without `./` python script; * `rm_dir` – adds `-rf` when you trying to remove directory; -* `sudo` – prepends `sudo` to previous command if it failed because of permissions. +* `sudo` – prepends `sudo` to previous command if it failed because of permissions; +* `switch_layout` – switches command from your local layout to en. ## Creating your own rules diff --git a/setup.py b/setup.py index 8172174a..1545274b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup(name='thefuck', - version=1.15, + version=1.16, description="Magnificent app which corrects your previous console command", author='Vladimir Iakovlev', author_email='nvbn.rm@gmail.com', diff --git a/tests/rules/test_switch_lang.py b/tests/rules/test_switch_lang.py new file mode 100644 index 00000000..363d6417 --- /dev/null +++ b/tests/rules/test_switch_lang.py @@ -0,0 +1,18 @@ +# -*- encoding: utf-8 -*- + +from mock import Mock +from thefuck.rules import switch_lang + + +def test_match(): + assert switch_lang.match(Mock(stderr='command not found: фзе-пуе', + script=u'фзе-пуе'), None) + assert not switch_lang.match(Mock(stderr='command not found: pat-get', + script=u'pat-get'), None) + assert not switch_lang.match(Mock(stderr='some info', + script=u'фзе-пуе'), None) + + +def test_get_new_command(): + assert switch_lang.get_new_command( + Mock(script=u'фзе-пуе штыефдд мшь'), None) == 'apt-get install vim' diff --git a/thefuck/rules/switch_lang.py b/thefuck/rules/switch_lang.py new file mode 100644 index 00000000..aa75e5f2 --- /dev/null +++ b/thefuck/rules/switch_lang.py @@ -0,0 +1,29 @@ +# -*- encoding: utf-8 -*- + +target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''' + +source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,'''] + + +def _get_matched_layout(command): + for source_layout in source_layouts: + if all([ch in source_layout or ch in '-_' + for ch in command.script.split(' ')[0]]): + return source_layout + + +def match(command, settings): + return 'not found' in command.stderr and _get_matched_layout(command) + + +def _switch(ch, layout): + if ch in layout: + return target_layout[layout.index(ch)] + else: + return ch + + +def get_new_command(command, settings): + matched_layout = _get_matched_layout(command) + return ''.join(_switch(ch, matched_layout) for ch in command.script) +