I think everyone at least once neatly selecting a piece of code \ console command from the window of your favorite browser, pressing "ctrl + c", then "ctrl + v" in the active window of the terminal emulator was very surprised - "\ n" accidentally turned out to be selected, respectively, you already ran the command .
I offer an easy and simple solution to this problem. Since
the best programming language is python, this is the only thing that I somehow know, we will use it.
Total - you need to intercept the data from the clipboard by pressing "ctrl + v", check for the presence of "\ n" and then "call" ctrl + v. It is not logical to do a buffer check for all application programs, and for example in gnome-terminal “Paste” is assigned to “Shift + Ctrl + V” by default, then I replaced it with “Ctrl + V”. Next you need to put a buffer check on the usual combination “Shift + Ctrl + V”.
There are many options to do this that depend on the working environment used. Specifically, in my case it is
')
~ / .config / openbox / rc.xml
<keyboard> <keybind key="SCv"> <action name="Execute"> <command>/home/user/scripts/safe_paste.py</command> </action> </keybind> </keyboard>
Do not forget chmod + x /home/user/scripts/safe_paste.py.
/home/user/scripts/safe_paste.py
/home/user/scripts/paste_it.py
Splitting the code into 2 files will give a slight performance boost, of course, and you can immediately assign paste_it.py.
In addition to the "\ n",
www.asciitable.com , namely, 0-31 and 127, which can also cause unexpected terminal behavior, can get into the buffer, therefore you need to inform about it.
Next you need to call "crtl + v" to insert a safe text. Well, if the content is not safe, then open the text editor \ throw away some characters \ remove "\ n" automatically, then it is already more convenient for someone, the implementation will also not be difficult. For me personally, it is enough to know that I have touched something extra when selecting.
There were many ways to call “ctrl + v” from under Linux:
- xdotool - a wonderful thing at a glance - in Centos 6.3 there are no turnips, it was not possible to collect
- xvkbd - collected by imake (Imake is a deprecated source configuration), but not assembled
- python-uinput - from gun on sparrows, device emulation, hal rule
- python-virtkey - also not collected
- xautomation - it was in turnips, but very ancient and it worked terribly, and stuck ctrl
- under windows there is autohotkey, autoit, pywin32
Need to write yourself.
On the c / s ++, I scored a walk, since it would not kick the floor.
A very compact java solution was implemented:
PasteIt.java
import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; public class PasteIt{ public static void main(String[] args) { try { Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.delay(20); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); } catch (AWTException e) { e.printStackTrace(); } } }
javac PasteIt.java
On a not entirely new laptop, the call of this class took 1-2 seconds, it was not very comfortable, but it worked.
Gcj looks abandoned but
gcj -O2 --main = PasteIt PasteIt.java
and the a.out binary was created, which I renamed to pasteit and it works 0.1 sec.
Now, as usual, I press “ctrl + shift + v”, and if something is not suitable in the buffer, then I will receive a notification, as I can use “ctrl + v” if I need to insert data without checking.
The solution turned out to be not the best, pulling a bunch of technologies, but the code turned out to be very compact and clear, which will easily allow everyone to adjust everything for themselves. The performance turned out quite normal.
Replacing xsel with
stackoverflow.com solutions, using
mingw , you can also use GCJ, but I’m not quite sure of the need for all of this to use in powershell \ cmd, but it may be useful for putty.