Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
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 141462a
Author: RealOrge <45096491+RealOrge@users.noreply.github.com>
Date:   Thu Dec 13 16:47:43 2018 +0200

    Update switch_lang.py

commit 1f79285
Author: RealOrge <45096491+RealOrge@users.noreply.github.com>
Date:   Thu Dec 13 16:39:04 2018 +0200

    Update switch_lang.py

commit e7dede5
Author: RealOrge <45096491+RealOrge@users.noreply.github.com>
Date:   Thu Dec 13 15:24:10 2018 +0200

    Update switch_lang.py

commit 4a0a973
Author: RealOrge <45096491+RealOrge@users.noreply.github.com>
Date:   Thu Dec 13 15:04:44 2018 +0200

    Update switch_lang.py

commit 80d6b8d
Author: RealOrge <45096491+RealOrge@users.noreply.github.com>
Date:   Thu Dec 13 14:25:15 2018 +0200

    Update switch_lang.py

commit 66b13c5
Author: RealOrge <45096491+RealOrge@users.noreply.github.com>
Date:   Thu Dec 13 11:44:48 2018 +0200

    Update switch_lang.py
  • Loading branch information
nvbn committed Jan 14, 2019
1 parent b946b7d commit 8093f7c
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions thefuck/rules/switch_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down

0 comments on commit 8093f7c

Please sign in to comment.