-
-
Notifications
You must be signed in to change notification settings - Fork 894
Add support for jsonnet #4378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for jsonnet #4378
Conversation
|
I decided to take a shot at adding jsonnet support directly. Let me know if this is the right approach. |
|
Thank you for PR! With this approach, changes written back to the JSON from the settings window or the menu aren't reflected. At the moment, I think the best approach is to manually convert karabiner.jsonnet to karabiner.json when you make changes. Separately from that, I understand how painful it is to write JSON directly. "profiles": [
{
"complex_modifications": {
"rules": [
{
"description": "local",
"manipulators": {"eval": "external.js"}
}
]
}
}
] |
|
That makes sense. Personally I do not like the settings window changing my karabiner config, but to a casual user it might be confusing to not have to read changes read back. What if we do this: if karabiner.jsonnet and karabiner.json files both exist, we merge the two? That way karabiner can write back changes to karabiner.json and those will be respected without any further changes. Power users can continue using the jsonnet file and that will continue working. Pseudocode: jsonnet_cfg = try_read_jsonnet() or {}
json_cfg = try_read_json() or {}
return json.merge(json_cfg, jsonnet_cfg)Regarding using duktape, I think it is worth noting that jsonnet is the standard for "programmable json". It has a healthy ecosystem including editor and language server support. Whereas, most editors don't know what to do with eval statements inside a json files. What do you think? |
|
Jsonnet itself is fine, but I'm a bit concerned about how weak it is in terms of stopping malicious scripts. Without a way to interrupt things like semi-infinite loops as follows, it would be hard to adopt... local fib(n) =
if n < 2 then n
else fib(n-1) + fib(n-2);
fib(45) |
|
What if we use |
|
Hmm, if we were to integrate this into the core, I'd really want to handle it directly with libjsonnet… |
|
In the latest beta (v15.9.5), you can now define rules using JavaScript, so please give it a try. Editing with an external editor is recommended.
|


fixes #3320