-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselected_convert.sh
33 lines (23 loc) · 1.22 KB
/
selected_convert.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
# Script to convert selected string to another layout (Eng <=> Rus)
# No Wayland support, works in X11 only, but without any daemons needed
# 2023.07.14
# Save current clipboard
CLIPBOARD_2_RESTORE=$(xsel -ob)
# Clean keys you use to call script (in my case it's ctrl-shift-F12)
xdotool keyup --delay 20 Control_L+Shift_L+F12
# Send selection to sed, convert all to target layout, then send result to clipboard
xsel -o | sed "y/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ[]{};':\",.\/<>?@#\$^&\`~фисвуапршолдьтщзйкыегмцчняФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯхъХЪжэЖЭбюБЮ№ёЁ/фисвуапршолдьтщзйкыегмцчняФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯхъХЪжэЖЭбю.БЮ,\"№;:?ёЁabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ[]{};':\",.<>#\`~/" | xsel -ib
# Clean modifiers we are going to use
xdotool keyup Shift_L+Insert
# Paste clipboard into selection
xdotool key --delay 20 Shift_L+Insert
# Wipe clipboard
xsel --clear
# Restore clipboard
echo -n $CLIPBOARD_2_RESTORE | xsel -bi
# Switch keyboard layout
xdotool key Mode_switch
# Finally clean all modifiers used
xdotool keyup Shift_L+Control_L+Shift_L+Insert
exit 0