mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 12:06:04 +00:00
Squashed commit of the following:
commit b853385ea9b9409a29a30c7af4d47c9a500cd287 Author: Vladimir Iakovlev <nvbn.rm@gmail.com> Date: Tue Jan 15 00:54:01 2019 +0100 #864: Make the solution for Greek a bit more extensible commit 073ebceb594ad24972f7765b1f608de44c1cebf2 Merge: b946b7d 141462a Author: Vladimir Iakovlev <nvbn.rm@gmail.com> Date: Tue Jan 15 00:46:09 2019 +0100 Merge branch 'master' of git://github.com/RealOgre/thefuck into RealOgre-master commit 141462a6fbe51832276b97d2143b2e26c138addc Author: RealOrge <45096491+RealOrge@users.noreply.github.com> Date: Thu Dec 13 16:47:43 2018 +0200 Update switch_lang.py commit 1f792853f25999448da656fb8724df6aba4ba03d Author: RealOrge <45096491+RealOrge@users.noreply.github.com> Date: Thu Dec 13 16:39:04 2018 +0200 Update switch_lang.py commit e7dede53a19db78b486463c32077557ff6ebf342 Author: RealOrge <45096491+RealOrge@users.noreply.github.com> Date: Thu Dec 13 15:24:10 2018 +0200 Update switch_lang.py commit 4a0a973e62b497225534e26b05c7909e48ed1b52 Author: RealOrge <45096491+RealOrge@users.noreply.github.com> Date: Thu Dec 13 15:04:44 2018 +0200 Update switch_lang.py commit 80d6b8da4c77452f8f13988b79b6b7e2a9d63c9e Author: RealOrge <45096491+RealOrge@users.noreply.github.com> Date: Thu Dec 13 14:25:15 2018 +0200 Update switch_lang.py commit 66b13c53b367e7c47df9da14da67d35dfc651152 Author: RealOrge <45096491+RealOrge@users.noreply.github.com> Date: Thu Dec 13 11:44:48 2018 +0200 Update switch_lang.py
This commit is contained in:
parent
b946b7d319
commit
8093f7cab8
@ -2,22 +2,42 @@
|
||||
from thefuck.utils import memoize, get_alias
|
||||
|
||||
target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?'''
|
||||
# any new keyboard layout must be appended
|
||||
|
||||
greek = u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?'''
|
||||
|
||||
source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''',
|
||||
u'''йцукенгшщзхїфівапролджєячсмитьбю.ЙЦУКЕНГШЩЗХЇФІВАПРОЛДЖЄЯЧСМИТЬБЮ,''',
|
||||
u'''ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپو./ًٌٍَُِّْ][}{ؤئيإأآة»«:؛كٓژٰٔء><؟''',
|
||||
u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?''',
|
||||
u'''/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''']
|
||||
u'''/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''',
|
||||
greek]
|
||||
|
||||
|
||||
source_to_target = {
|
||||
greek: {u';': "q", u'ς': "w", u'ε': "e", u'ρ': "r", u'τ': "t", u'υ': "y",
|
||||
u'θ': "u", u'ι': "i", u'ο': "o", u'π': "p", u'[': "[", u']': "]",
|
||||
u'α': "a", u'σ': "s", u'δ': "d", u'φ': "f", u'γ': "g", u'η': "h",
|
||||
u'ξ': "j", u'κ': "k", u'λ': "l", u'΄': "'", u'ζ': "z", u'χ': "x",
|
||||
u'ψ': "c", u'ω': "v", u'β': "b", u'ν': "n", u'μ': "m", u',': ",",
|
||||
u'.': ".", u'/': "/", u':': "Q", u'΅': "W", u'Ε': "E", u'Ρ': "R",
|
||||
u'Τ': "T", u'Υ': "Y", u'Θ': "U", u'Ι': "I", u'Ο': "O", u'Π': "P",
|
||||
u'{': "{", u'}': "}", u'Α': "A", u'Σ': "S", u'Δ': "D", u'Φ': "F",
|
||||
u'Γ': "G", u'Η': "H", u'Ξ': "J", u'Κ': "K", u'Λ': "L", u'¨': ":",
|
||||
u'"': '"', u'Ζ': "Z", u'Χ': "X", u'Ψ': "C", u'Ω': "V", u'Β': "B",
|
||||
u'Ν': "N", u'Μ': "M", u'<': "<", u'>': ">", u'?': "?", u'ά': "a",
|
||||
u'έ': "e", u'ύ': "y", u'ί': "i", u'ό': "o", u'ή': 'h', u'ώ': u"v",
|
||||
u'Ά': "A", u'Έ': "E", u'Ύ': "Y", u'Ί': "I", u'Ό': "O", u'Ή': "H",
|
||||
u'Ώ': "V"},
|
||||
}
|
||||
|
||||
|
||||
@memoize
|
||||
def _get_matched_layout(command):
|
||||
# don't use command.split_script here because a layout mismatch will likely
|
||||
# result in a non-splitable sript as per shlex
|
||||
# result in a non-splitable script as per shlex
|
||||
cmd = command.script.split(' ')
|
||||
for source_layout in source_layouts:
|
||||
is_all_match = True
|
||||
|
||||
for cmd_part in cmd:
|
||||
if not all([ch in source_layout or ch in '-_' for ch in cmd_part]):
|
||||
is_all_match = False
|
||||
@ -35,12 +55,18 @@ def _switch(ch, layout):
|
||||
|
||||
|
||||
def _switch_command(command, layout):
|
||||
# Layouts with different amount of characters than English
|
||||
if layout in source_to_target:
|
||||
return ''.join(source_to_target[layout].get(ch, ch)
|
||||
for ch in command.script)
|
||||
|
||||
return ''.join(_switch(ch, layout) for ch in command.script)
|
||||
|
||||
|
||||
def match(command):
|
||||
if 'not found' not in command.output:
|
||||
return False
|
||||
|
||||
matched_layout = _get_matched_layout(command)
|
||||
return (matched_layout and
|
||||
_switch_command(command, matched_layout) != get_alias())
|
||||
|
Loading…
x
Reference in New Issue
Block a user