-
Notifications
You must be signed in to change notification settings - Fork 23
/
s2cctl
executable file
·45 lines (39 loc) · 1.5 KB
/
s2cctl
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
#! /bin/sh
logfile="$HOME/.Space2Ctrl.log"
start() {
origmap=$(xmodmap -pke | grep -E "^keycode[[:blank:]]*?65")
#newmap=$(echo ${origmap} | perl -pe "s/65[[:blank:]]*?=[[:blank:]]*?space/65 = Control_L/")
newmap=$(echo ${origmap} | perl -pe "s/ space/ Control_L/g")
xmodmap -e "$newmap"
xmodmap -e "keycode 255 = space VoidSymbol VoidSymbol VoidSymbol VoidSymbol"
# Lousy way to get the current (active) XServer display
# https://unix.stackexchange.com/questions/203844/how-to-find-out-the-current-active-xserver-display-number
display=$(who | awk -v term="`cat /sys/class/tty/tty0/active`" '/\(:/ $0 ~ term { gsub(/\(|\)/, "", $0); print $5 }')
# Run s2c automatically passing the current display as parameter
nohup ${0%/*}/s2c $display >> "$logfile" 2>&1 &
sleep 1 # Don't ask me why but we need to wait more than one second else the ctrl modifier is
# reinitialized to XK_Control_L XK_Control_R as soon as keycode 65 is pressed!
`xmodmap -e "add control = Control_L Control_R"`
echo "Space2Ctrl is now active (logfile: $logfile)"
exit 0
}
stop() {
origmap=$(xmodmap -pke | grep -E "^keycode[[:blank:]]*?65")
newmap=$(echo ${origmap} | perl -pe "s/ Control_L/ space/g")
xmodmap -e "$newmap"
xmodmap -e "keycode 255 ="
xmodmap -e "clear control"
xmodmap -e "add control = Control_L"
xmodmap -e "add control = Control_R"
kill -s TERM `pgrep s2c` 2>&1
}
case $1 in
start)
echo "Starting Space2Ctrl..."
start;;
stop)
echo "Stopping Space2Ctrl..."
stop;;
*)
echo "Please pass start or stop";;
esac