Closed MattSturgeon closed 1 year ago
Hey, thanks for the nice thought out post. For this I prefer to use YAML anchors and aliases. Even though I am not a fan of most of YAML's features, this is one that came in handy frequently. Basically, you can assign an anchor to a node with &ref
syntax and refer to it later via *ref
, a contrived example:
LGUI: &lgui
tap: $$mdi:monitor-dashboard$$
held: Left
LEFT_GUI: *lgui
# above keys have identical values
RGUI:
<<: *lgui
held: Right
# overrides `held` field from above two
(As an aside, I find oq
helpful to work with yamls, e.g. oq -i yaml -o simpleyaml
can expand aliases like above and print the final result.)
You can see I (ab)use this in the keyboard layouts YAML to reduce repetition: https://github.com/caksoylar/keymap-drawer/blob/main/resources/zmk_keyboard_layouts.yaml
This is similar to your approach 1 in principle, except it is using the configuration syntax features rather than a feature from the keymap-drawer side. Let me know what you think, i.e. if that is good enough. I'd prefer to not add complexity if not needed.
Thanks. I didn't know yaml had an alias system, that'll come in handy.
That does exactly what I was asking for, probably better than any of my proposals.
I've noticed that since ZMK has so many duplicate keybind definitions, I end up with excessively large binding maps:
Solution 1: Inheritance
One strategy to to mitigate this would be an
inherit
,base
, orextend
field:This could also be used for similar binds, as aything defined on the inheriting bind would override the base definition.
One complexity would be recursive binds. These should produce an error:
Approach 2: Aliases
A different approach might be to have an "also applies to" field:
If a bind is defined multiple times, they could be combined (similar to inheritance) or simply let the one defined last override previous definitions (perhaps with a warning)?
Approach 3: Parse map keys into lists
Another approach would be mapping
list->bind
instead ofstring->bind
, however since yaml doesn't have syntax for that we'd have to invent our own:Personally, I think the approach 2 (aliases) works best :thinking: