forked from system76/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayouts.sh
executable file
·67 lines (62 loc) · 1.35 KB
/
layouts.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
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only
# This script produces layout data for the System76 Keyboard Configurator
set -e
rm -rf build/layouts
mkdir -p build/layouts
D="$(realpath build/layouts)"
binary="$D/keymap"
source="$binary.c"
header="tmk_core/common/keycode.h"
echo "#include <stdio.h>" > "$source"
echo "#include \"$header\"" >> "$source"
echo "int main(int argc, char **argv) {" >> "$source"
grep '^ KC_' "$header" \
| cut -d ' ' -f5 \
| cut -d ',' -f1 \
| while read keycode
do
name="$(echo "$keycode" | cut -d '_' -f2-)"
echo "printf(\"${name},0x%04X\\n\", $keycode);" >> "$source"
done
echo "return 0;" >> "$source"
echo "}" >> "$source"
gcc -I. "$source" -o "$binary"
"$binary" | tee "$D/keymap.csv"
cd keyboards/
for board in system76/launch_*
do
file="$board/$(basename "$board").h"
if [ ! -e "$file" ]
then
continue
fi
echo "# $board"
mkdir -p "$D/$board"
cp "$D/keymap.csv" "$D/$board"
row=0
rg \
--multiline \
--multiline-dotall \
--regexp '#define LAYOUT\(.*\) \{.*\}' \
"$file" \
| grep --only-matching '\{.*\}' \
| sed 's/^{ //' \
| sed 's/ }$//' \
| sed 's/, / /g' \
| while read line
do
col=0
for word in $line
do
if [ "$word" != "___" ]
then
echo "$word,$row,$col"
fi
col=$(expr $col + 1)
done
row=$(expr $row + 1)
done \
| sort -n \
| tee "$D/${board}/layout.csv"
done