📜 ⬆️ ⬇️

Useful stuff: recoding wrong layout

It often happens that the text is typed in the wrong layout.
Possession of the method of blind dialing, of course, significantly reduces this probability, but incidents still happen.
It is especially annoying if the text is quite large and to re-type laziness.


1. unix way

The most obvious thing is to write a transcoder from stdin to stdout:
#!/usr/bin/perl -CS
use utf8;
$lat=q(`~!@#$%^&qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?);
$cyr=q(!"№;%:?./,);
while(<>) { eval "tr{$lat$cyr}{$cyr$lat}"; print; }

/ * '-CS' here sets the utf8 encoding for stdin and stdout, 'use utf8' - the encoding of the script text itself.
In principle, you can shove all this into a one-liner:
perl -CS -Mutf8 -pe 'tr/qwerty....../...qwert.../;'
* /
Upd:
Instead of perl, you can use a more default sed:
sed -e 'y/qwerty....../...qwerty.../'

This script is quite natural to tie, for example, in the klipper from kde:
For a regular expression .* (Any text), command: echo -n "%s" | translit echo -n "%s" | translit
There is probably something similar in the gnome.
However, calling it is not very convenient, since klipper does not know how to add hot keys to individual actions:
  1. Select text
  2. Put in buffer
  3. Call the action menu
  4. Select an action (by cursor)
  5. Insert text from the buffer


2. xclip

With the help of xclip utility, you can pull the text out of the buffer and put it back.
And you can handle both the clipboard (clipboard), and the text selected by the mouse (primary selection).
Team: xclip -out | translit | xclip -in xclip -out | translit | xclip -in
Recodes the selection with the left mouse button, the result can be inserted with the middle mouse button.
To process not the mouse selection, but the clipboard:
xclip -out -sel clip| translit | xclip -in -sel clip

3. xdotool

There is no universal command “put selected text into buffer / from buffer” in X.
But in most programs this is done by pressing Ctrl-C / Ctrl-V.
Pressing these keys can be simulated with the xdotool utility.
The team will result in the following:
xdotool key 'ctrl+c'; xclip -out -sel clip | translit | xclip -in -sel clip; xdotool key 'ctrl+v'
It can be hung on a global hot-key.
  1. Select the text as you like
  2. Push hot key

')

Source: https://habr.com/ru/post/105104/


All Articles