forked from sergei-mironov/xkb-switch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxkb-group.sh
executable file
·68 lines (58 loc) · 1.4 KB
/
xkb-group.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
#!/bin/sh
die() { echo $@ >&2 ; exit 1 ; }
# debug() { echo $@ >&2 ; }
debug() { return 0 ;}
usage() { (
printf "`basename $0` waits for any user input, then switches between primary and secondary layout\n"
printf "Usage: `basename $0` LAY1 LAY2\n"
printf "Where\n"
printf "\tLAY1 - primary layout\n"
printf "\tLAY2 - initial secondary layout\n"
printf "Example:\n"
printf "`basename $0` us ru - switches between 'us' and some secondary layout, initially 'ru'\n"
)>&2 ; }
while test -n "$1" ; do
case $1 in
-h|--help)
usage ; die ;;
*)
lay1=$1
lay2=$2
shift
;;
esac
shift
done
test -n "$lay1" || { die "error: LAY1 is empty, try --help"; }
test -n "$lay2" || { die "error: LAY2 is empty, try --help"; }
FIFO=/tmp/$USER-kde-groups-emu.fifo
rm $FIFO >/dev/null 2>&1
mkfifo $FIFO 2>/dev/null || die "Failed to create $FIFO"
while read event arg <$FIFO ; do
debug "$event $arg" >&2
case $event in
layout-change)
lay=$arg
case $lay in
$lay1) next=$lay2;;
*) next=$lay1
lay2=$lay;;
esac
;;
user-asks-switch)
xkb-switch -s $next ;;
*)
echo "unknown command: $event $arg" >&2
;;
esac
done &
echo layout-change `xkb-switch -p` >$FIFO
xkb-switch -W | while read l ;do
echo "layout-change $l" >$FIFO
done &
trap "pkill -P $$; exit" SIGINT
trap "pkill -P $$; exit" SIGTERM
trap "pkill -P $$; exit" EXIT
while read l ; do
echo "user-asks-switch $l" >$FIFO
done