Skip to content

Instantly share code, notes, and snippets.

@Innf107
Created March 16, 2023 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Innf107/17bb7fd6d6d31c887dc9f800310c1869 to your computer and use it in GitHub Desktop.
Save Innf107/17bb7fd6d6d31c887dc9f800310c1869 to your computer and use it in GitHub Desktop.
#!/usr/bin/env polaris
module List = import("../polaris/lib/list.pls")
let filterMap : forall a b. (a -> < Nothing, Just(b) > , List(a)) -> List(b)
let filterMap(f, list) = match list {
[] -> []
(x :: xs) -> match f(x) {
Nothing -> filterMap(f, xs)
Just(y) -> y :: filterMap(f, xs)
}
}
let join(separator, list) = match list {
[] -> ""
[x] -> x
(x :: xs) -> x ~ separator ~ join(separator, xs)
}
let bindMaybe : forall a b m. (< Nothing, Just(a) > , a -> < Nothing, Just(b) | m >) -> < Nothing, Just(b) | m >
let bindMaybe(maybe, cont) = match maybe {
Nothing -> Nothing
Just(x) -> cont(x)
}
let keyBindings(content) = {
match regexpMatchGroups("key <(.*?)>", content) {
[[_, key]] -> match regexpMatchGroups("\[(.*?)\]", content) {
[[_, bindingString]] | [[_, _], [_, bindingString]] -> {
let bindings = split(",", bindingString)
Just({ key=key, bindings=bindings })
}
_ -> Nothing
}
_ -> Nothing
}
}
let bindingsFor : String -> List({ key : String, bindings : List(String) })
let bindingsFor(file) = {
# This works around the current lack of string escapes in polaris
let pattern = !echo "-e" "key(.|\n)*?;"
let keys = regexpMatch(pattern, !cat file)
filterMap(keyBindings, keys)
}
let renderBinding(binding) =
" key <" ~ binding.key ~ "> { [" ~ join(", ", binding.bindings) ~ "] };"
let merge(neo, qwertz) = {
match (neo.bindings, qwertz.bindings) {
((_neo1 :: _neo2 :: neo3 :: neoRest), (qwertz1 :: qwertz2 :: qwertzRest)) -> {
let bindings = qwertz1 :: qwertz2 :: neo3 :: neoRest
Just({ key = neo.key, bindings = bindings })
}
_ -> Nothing
}
}
let neoqwertzBindings = bindingsFor("neoqwertz_full")
let qwertzBindings = bindingsFor("qwertz_full")
let merged = filterMap((\neo -> bindMaybe(List.find(\q -> q.key == neo.key, qwertzBindings), \q -> merge(neo, q))), neoqwertzBindings)
List.for(merged, \binding -> print(renderBinding(binding)))
default
xkb_symbols "novusqwertz" {
include "de(neo_qwertz_base)"
name[Group1]="German (NovusQWERTZ)";
// <GENERATED>
key <AE01> { [ 1, exclam, onesuperior, onesubscript, ordfeminine, NoSymbol, notsign, NoSymbol ] };
key <AE02> { [ 2, quotedbl, twosuperior, twosubscript, masculine, NoSymbol, logicalor, NoSymbol ] };
key <AE03> { [ 3, section, threesuperior, threesubscript, numerosign, NoSymbol, logicaland, NoSymbol ] };
key <AE04> { [ 4, dollar, U203A, femalesymbol, NoSymbol, NoSymbol, U22A5, NoSymbol ] };
key <AE05> { [ 5, percent, U2039, malesymbol, periodcentered, NoSymbol, U2221, NoSymbol ] };
key <AE06> { [ 6, ampersand, cent, U26A5, sterling, NoSymbol, U2225, NoSymbol ] };
key <AE07> { [ 7, slash, yen, U03F0, currency, NoSymbol, rightarrow, NoSymbol ] };
key <AE08> { [ 8, parenleft, singlelowquotemark, U27E8, Tab, ISO_Left_Tab, U221E, NoSymbol ] };
key <AE09> { [ 9, parenright, leftsinglequotemark, U27E9, KP_Divide, KP_Divide, variation, NoSymbol ] };
key <AE10> { [ 0, equal, rightsinglequotemark, zerosubscript, KP_Multiply, KP_Multiply, emptyset, NoSymbol ] };
key <AE11> { [ ssharp, question, NoSymbol, Greek_finalsmallsigma, KP_Subtract, KP_Subtract, jot, NoSymbol ] };
key <AE12> { [ dead_acute, dead_grave, dead_abovering, dead_abovereversedcomma, dead_diaeresis, NoSymbol, dead_macron, NoSymbol ] };
key <TAB> { [ Tab, ISO_Left_Tab , Multi_key, ISO_Level5_Lock, NoSymbol, NoSymbol, NoSymbol, ISO_Level5_Lock ] };
key <AD01> { [ q, Q, ellipsis, U03D5, Prior, Prior, U211A, NoSymbol ] };
key <AD02> { [ w, W, underscore, Greek_omega, BackSpace, BackSpace, Greek_OMEGA, NoSymbol ] };
key <AD03> { [ e, E, bracketleft, Greek_epsilon, Up, Up, U2203, NoSymbol ] };
key <AD04> { [ r, R, bracketright, Greek_rho, Delete, Delete, U211D, NoSymbol ] };
key <AD05> { [ t, T, asciicircum, Greek_tau, Next, Next, partialderivative, NoSymbol ] };
key <AD06> { [ z, Z, exclam, Greek_zeta, exclamdown, NoSymbol, U2124, NoSymbol ] };
key <AD07> { [ u, U, less, Greek_psi, KP_7, KP_7, includedin, NoSymbol ] };
key <AD08> { [ i, I, greater, Greek_iota, KP_8, KP_8, integral, NoSymbol ] };
key <AD09> { [ o, O, equal, Greek_omicron, KP_9, KP_9, elementof, NoSymbol ] };
key <AD10> { [ p, P, ampersand, Greek_pi, KP_Add, KP_Add, Greek_PI, NoSymbol ] };
key <AD11> { [ udiaeresis, Udiaeresis, U017F, Greek_finalsmallsigma, U2212, NoSymbol, union, NoSymbol ] };
key <AD12> { [ plus, asterisk, dead_stroke, dead_abovecomma, dead_doubleacute, NoSymbol, dead_breve, NoSymbol ] };
key <AC01> { [ a, A, backslash, Greek_alpha, Home, Home, U2200, NoSymbol ] };
key <AC02> { [ s, S, slash, Greek_sigma, Left, Left, Greek_SIGMA, NoSymbol ] };
key <AC03> { [ d, D, braceleft, Greek_delta, Down, Down, Greek_DELTA, NoSymbol ] };
key <AC04> { [ f, F, braceright, Greek_phi, Right, Right, Greek_PHI, NoSymbol ] };
key <AC05> { [ g, G, asterisk, Greek_gamma, End, End, Greek_GAMMA, NoSymbol ] };
key <AC06> { [ h, H, question, Greek_psi, questiondown, NoSymbol, Greek_PSI, NoSymbol ] };
key <AC07> { [ j, J, parenleft, Greek_theta, KP_4, KP_4, Greek_THETA, NoSymbol ] };
key <AC08> { [ k, K, parenright, Greek_kappa, KP_5, KP_5, multiply, NoSymbol ] };
key <AC09> { [ l, L, minus, Greek_lamda, KP_6, KP_6, Greek_LAMDA, NoSymbol ] };
key <AC10> { [ odiaeresis, Odiaeresis, colon, U03F5, KP_Separator, comma, intersection, NoSymbol ] };
key <AC11> { [ adiaeresis, Adiaeresis, at, Greek_eta, period, KP_Decimal, U2135, NoSymbol ] };
key <TLDE> { [ dead_circumflex, degree, U21BB, U02DE, dead_abovedot, Pointer_EnableKeys, dead_belowdot, NoSymbol ] };
key <AB01> { [ y, Y, numbersign, Greek_upsilon, Escape, Escape, nabla, NoSymbol ] };
key <AB02> { [ x, X, dollar, Greek_xi, Tab, Tab, Greek_XI, NoSymbol ] };
key <AB03> { [ c, C, bar, Greek_chi, Insert, Insert, U2102, NoSymbol ] };
key <AB04> { [ v, V, asciitilde, Greek_pi, Return, Return, radical, NoSymbol ] };
key <AB05> { [ b, B, grave, Greek_beta, Undo, Redo, U21D0, NoSymbol ] };
key <AB06> { [ n, N, plus, Greek_nu, colon, NoSymbol, U2115, NoSymbol ] };
key <AB07> { [ m, M, percent, Greek_mu, KP_1, KP_1, ifonlyif, NoSymbol ] };
key <AB08> { [ comma, semicolon, quotedbl, U03F1, KP_2, KP_2, U21D2, NoSymbol ] };
key <AB09> { [ period, colon, apostrophe, U03D1, KP_3, KP_3, U21A6, NoSymbol ] };
key <AB10> { [ minus, underscore, semicolon, U2011, semicolon, NoSymbol, hyphen, NoSymbol ] };
key <KPMU> { [ KP_Multiply, KP_Multiply, U22C5, U2299, multiply, NoSymbol, U2297, NoSymbol ] };
key <FK01> { [ F1, F1, F1, F1, XF86Switch_VT_1 ] };
key <FK02> { [ F2, F2, F2, F2, XF86Switch_VT_2 ] };
key <FK03> { [ F3, F3, F3, F3, XF86Switch_VT_3 ] };
key <FK04> { [ F4, F4, F4, F4, XF86Switch_VT_4 ] };
key <FK05> { [ F5, F5, F5, F5, XF86Switch_VT_5 ] };
key <FK06> { [ F6, F6, F6, F6, XF86Switch_VT_6 ] };
key <FK07> { [ F7, F7, F7, F7, XF86Switch_VT_7 ] };
key <FK08> { [ F8, F8, F8, F8, XF86Switch_VT_8 ] };
key <FK09> { [ F9, F9, F9, F9, XF86Switch_VT_9 ] };
key <FK10> { [ F10, F10, F10, F10, XF86Switch_VT_10 ] };
key <KP7> { [ KP_Home, KP_7 , U2195, U226A, KP_Home, KP_Home, upstile, NoSymbol ] };
key <KP8> { [ KP_Up, KP_8 , uparrow, intersection, KP_Up, KP_Up, U22C2, NoSymbol ] };
key <KP9> { [ KP_Prior, KP_9 , U20D7, U226B, KP_Prior, KP_Prior, U2309, NoSymbol ] };
key <KPSU> { [ KP_Subtract, KP_Subtract, U2212, U2296, U2216, NoSymbol, U2238, NoSymbol ] };
key <KP4> { [ KP_Left, KP_4 , leftarrow, includedin, KP_Left, KP_Left, U2286, NoSymbol ] };
key <KP5> { [ KP_Begin, KP_5 , colon, U22B6, KP_Begin, KP_Begin, U22B7, NoSymbol ] };
key <KP6> { [ KP_Right, KP_6 , rightarrow, includes, KP_Right, KP_Right, U2287, NoSymbol ] };
key <KPAD> { [ KP_Add, KP_Add, plusminus, U2295, U2213, NoSymbol, U2214, NoSymbol ] };
key <KP1> { [ KP_End, KP_1 , U2194, lessthanequal, KP_End, KP_End, downstile, NoSymbol ] };
key <KP2> { [ KP_Down, KP_2 , downarrow, union, KP_Down, KP_Down, U22C3, NoSymbol ] };
key <KP3> { [ KP_Next, KP_3 , U21CC, greaterthanequal, KP_Next, KP_Next, U230B, NoSymbol ] };
key <KP0> { [ KP_Insert, KP_0 , percent, U2030, KP_Insert, KP_Insert, U25A1, NoSymbol ] };
key <KPDL> { [ KP_Delete, KP_Separator , comma, minutes, KP_Delete, KP_Delete, seconds, NoSymbol ] };
key <LSGT> { [ less, greater, ISO_Level5_Shift, ISO_Level5_Shift, ISO_Level5_Lock, ISO_Level5_Lock, ISO_Level5_Lock, ISO_Level5_Lock ] };
key <FK11> { [ F11, F11, F11, F11, XF86Switch_VT_11 ] };
key <FK12> { [ F12, F12, F12, F12, XF86Switch_VT_12 ] };
key <KPDV> { [ KP_Divide, KP_Divide, division, U2300, U2044, NoSymbol, U2223, NoSymbol ] };
// </GENERATED >
// Manual overrides
key <AD01> { [ q, Q, Greek_OMEGA, Prior, at, Prior, U211A, NoSymbol ] };
key <AE07> { [ 7, slash, yen, currency, braceleft, NoSymbol, rightarrow, NoSymbol ] };
key <AE08> { [ 8, parenleft, singlelowquotemark, Tab, bracketleft, ISO_Left_Tab, U221E, NoSymbol ] };
key <AE09> { [ 9, parenright, leftsinglequotemark, KP_Divide, bracketright, KP_Divide, variation, NoSymbol ] };
key <AE10> { [ 0, equal, rightsinglequotemark, KP_Multiply, braceright, KP_Multiply, emptyset, NoSymbol ] };
key <AE11> { [ ssharp, question, NoSymbol, Greek_finalsmallsigma, backslash, KP_Subtract, jot, NoSymbol ] };
key <AD12> { [ plus, asterisk, dead_stroke, dead_doubleacute, asciitilde, NoSymbol, dead_breve, NoSymbol ] };
// No idea what this does exactly, but the version without it doesn't seem to work
key.type[Group1] = "EIGHT_LEVEL";
key <LSGT> {[ less, greater, bar, bar, bar, bar ]};
include "shift(both_capslock)"
include "level3(caps_switch)"
include "level5(ralt_switch_lock)"
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment