Simple utility to turn swipes into words -- "plugin" for wvkbd to enable swipe-typing under wayland SXMO.
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
|
#!/bin/sh
source "$(dirname "$0")/functions.sh"
swipeToQuery(){
swipe=$(echo "$1" | tr -d "'.\*\"\\^$\(\)")
printf '^'
printf "${swipe:0:2}"
if test "${swipe:2}"; then
printf "${swipe:2}" |grep -o . | xargs -I{} printf '\?%s' "{}"
fi
printf '$'
}
query(){
swipe="$2"
wordlist="$1"
wordfile="$wordlist"
if test -d "$wordlist"; then
wordfile=/dev/null
fl=$(firstLetter "$swipe")
ll=$(lastLetter "$swipe")
test -f "$wordlist/$fl$ll" && wordfile="$wordlist/$fl$ll"
fi
query=$(swipeToQuery "$swipe")
echo "query: $query" > /dev/stderr
# -m 1: just give first result
grep -m 1 "$query" "$wordfile"
}
while read -r line; do
test "$line" && query "$1" "$line" && printf '\n'
done
|