-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.rc.mappings.sh
executable file
·162 lines (102 loc) · 2.95 KB
/
.rc.mappings.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env sh
#
# Map some key combinations to particular characters. This is very useful when
# typing foreign characters (like ç) in an English keyboard layout.
#
# TODO: figure out why this is not working.
#
# To see all keycodes, run `xmodmap -pke` in your terminal.
#
. $HOME/bin/.rc.common
if [ "$1" = "reset" ]; then
# Resets the mappings in the current keyboard layout.
echo 'Reset!'
setxkbmap
echo 'Done!'
exit
fi
all_keycodes="$(xmodmap -pke)"
# Gets the keycodes for a key automatically. You might want to doublecheck the
# values once per new system, just to be sure.
get_keycode() {
# Echoing without double quotes merges all the lines into one, facilitating
# detection.
echo $all_keycodes | sed -E -e "s/.*keycode\s+([0-9]+)\s+=\s+$1 .*/\1/"
}
# This contains the string that should be searched in the output of xmodmap.
# The regex to get them considers that they are the first part of the string
# after the `=`, but that is not the case for `ccedilla`. Therefore we change
# the search string for something that will match.
k_alt_r='Alt_R'
k_alt_l='Alt_L'
k_shift_l='Shift_L'
alt_r="$(get_keycode $k_alt_r)"
debug "$k_alt_r = $alt_r"
alt_l="$(get_keycode $k_alt_l)"
debug "$k_alt_l = $alt_l"
shift_l="$(get_keycode $k_shift_l)"
debug "$k_shift_l = $shift_l"
# For a.
k_letter_a='a'
k_letter_q='q'
k_letter_z='z'
letter_a="$(get_keycode $k_letter_a)"
debug "$k_letter_a = $letter_a"
letter_q="$(get_keycode $k_letter_q)"
debug "$k_letter_q = $letter_q"
letter_z="$(get_keycode $k_letter_z)"
debug "$k_letter_z = $letter_z"
# For e.
k_letter_s='s'
letter_s="$(get_keycode $k_letter_s)"
debug "$k_letter_s = $letter_s"
# For i.
k_letter_d='d'
letter_d="$(get_keycode $k_letter_d)"
debug "$k_letter_d = $letter_d"
# For o.
k_letter_f='f'
k_letter_r='r'
letter_f="$(get_keycode $k_letter_f)"
debug "$k_letter_f = $letter_f"
letter_r="$(get_keycode $k_letter_r)"
debug "$k_letter_r = $letter_r"
# For u.
k_letter_g='g'
letter_g="$(get_keycode $k_letter_g)"
debug "$k_letter_g = $letter_g"
# For c.
k_letter_c='c'
letter_c="$(get_keycode $k_letter_c)"
debug "$k_letter_c = $letter_c"
if is_debug; then
exit
fi
# Mappings
# --------
# Keeping the most commonly used keys in home row, with alternatives up or down
# from it.
### Cedilla
# Alt_R + c -> ç
xmodmap -e "keycode $alt_r + $letter_c = ccedilla"
### Letter a
# Alt_R + a -> ã
xmodmap -e "keycode $alt_r + $letter_a = atilde"
# Alt_R + q -> á
xmodmap -e "keycode $alt_r + $letter_q = aacute"
# Alt_R + z -> à
xmodmap -e "keycode $alt_r + $letter_z = agrave"
### Letter e
# Alt_R + s -> é
xmodmap -e "keycode $alt_r + $letter_s = eacute"
### Letter i
# Alt_R + d -> í
xmodmap -e "keycode $alt_r + $letter_d = iacute"
### Letter o
# Alt_R + f -> õ
xmodmap -e "keycode $alt_r + $letter_f = otilde"
# Alt_R + r -> ó
xmodmap -e "keycode $alt_r + $letter_r = oacute"
### Letter u
# Alt_R + g -> ú
xmodmap -e "keycode $alt_r + $letter_g = uacute"