-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson2yaml
executable file
·21 lines (19 loc) · 1.13 KB
/
json2yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash
# Convert a QMK keymap.json & layout.h to keymap-drawer yaml
test -z "$QMK_HOME" && echo "Must set QMK_HOME to root qmk_firmware dir" && exit 1 || true
test -z "$(which qmk)" && echo "Must have qmk_cli installed" && exit 2 || true
test -z "$(which pcpp)" && echo "Must have pcpp cli installed" && exit 3 || true
test "$#" != 2 && echo "Usage: ./json2yaml qmk-keymap.json layout.h" && exit 4 || true
keymap_yaml='/tmp/keymap.yaml'
keymap_json="$1"
layout_h="$2"
# (1) Convert keymap.json (containing only layer name macros) to keymap.c
# (2) Expand layer macros (define KEYMAP_DISPLAY so that aliases for shortcuts are not expanded)
# (3) Convert keymap.c to QMK keymap.json
# (4) Parse fully expanded QMK keymap.json into yaml using keymap-drawer
qmk json2c "$keymap_json" -o /tmp/keymap-json.c 2> /dev/null
pcpp -D QMK_KEYBOARD_H="" -D KEYMAP_DISPLAY $layout_h /tmp/keymap-json.c > /tmp/keymap.c
qmk c2json -kb "$(jq -r '.keyboard' $keymap_json)" -km default /tmp/keymap.c > /tmp/keymap.json
layers=$(jq -cr ".layers[][0]" $keymap_json | sed 's|\s*\_||g')
keymap parse -l $layers -q /tmp/keymap.json > "$keymap_yaml"
cat "$keymap_yaml"