Last active
September 28, 2017 15:55
-
-
Save dallaylaen/470a92bfdce50308f4b582bd8cceed28 to your computer and use it in GitHub Desktop.
Decode russian words entered in wrong layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# If you use `xbindkeys` + `xsel`, here's how to make use of this script | |
# (it should be chmod +x and in your path, obviously) | |
# | |
# "xsel -o | ruslat.pl | xsel -i" | |
# Mod4 + q | |
# | |
# This maps the Super key (aka Win) + Q to this script and transcodes | |
# text in the clipboard | |
# So if you start typing in wrong kb layout, | |
# select the text you just entered and press Super+Q | |
# and paste the text with russian keys replaced with latin and vice-versa. | |
use strict; | |
use warnings; | |
use utf8; | |
binmode STDIN, ":utf8"; | |
binmode STDOUT, ":utf8"; | |
# letters and signs are separated so that we can UC them | |
# then I wash my keyb left to right, in English and Russian layout, respectively | |
my $lat = 'qwertyuiop'.'asdfghjkl'.'zxcvbnm'; | |
my $lat_p = '@#$%^&*_+'.'`[]\\;\',./'.'~{}|:"<>?'; | |
my $rus = 'йцукенгшщз'.'фывапролд'.'ячсмить'; | |
my $rus_p = '"№;%:?*_+'.'ёхъ\\жэбю.' .'ЁХЪ/ЖЭБЮ,'; | |
$lat .= $lat_p. uc $lat; | |
$rus .= $rus_p. uc $rus; | |
# yep, this is what `perldoc perlop` suggests | |
eval "sub conv { /[а-яё]/i ? y($rus)($lat) : y($lat)($rus) for \@_; \@_; }"; | |
die $@ if $@; | |
while (<>) { | |
print join "", conv(split /(\s+)/, $_); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment