aboutsummaryrefslogtreecommitdiff
path: root/editors/remap.bqn
blob: f1fe2da6a31f4b0fc1d7b9fa4dd899079ff14e41 (plain)
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
#! /usr/bin/env bqn

help  1"
Remap a BQN keyboard file from qwerty. Options:
  -h, --help: Print this message and exit
  -k: Output keyboard layout
  -i: Input file(s) in editors/
  -o: Output file(s); uses stdout if not given"

o  "-h""--help""-k""-i""-o"
oo  (o) = oi  o  ar•args
•Exit•Outhelp(´2>) oi
keyinpout  2o ar ˜ (¬-˜⊢× oi˜ ≠⌈`׬)oo

A  {𝕩?@; •Out 𝕨  •Exit 1}
"Can only specify one keyboard layout at a time!" A 1≥≠key
"No inputs!" A 0<≠inp
"Requires one output file for each input, or one input and no output to use stdout" A inp=(⊢+0=)out

Map  {𝕩˜𝕨⊐⊢}
_sl_  {𝔽_𝕣_a,b: 𝔽((ab↓⊢)¨)((a↑∾⊣∾b)¨)}

# Key layouts
qwerty    "`1234567890-=~!@#$%^&*()_+qwertyuiop[]QWERTYUIOP{}asdfghjkl;'ASDFGHJKL:""|zxcvbnm,./ZXCVBNM<>? "
keys  
  "dvorak""`1234567890[]~!@#$%^&*(){}',.pyfgcrl/=""<>PYFGCRL?+aoeuidhtns-AOEUIDHTNS_|;qjkxbmwvz:QJKXBMWVZ "
 "colemak""`1234567890-=~!@#$%^&*()_+qwfpgjluy;[]QWFPGJLUY:{}arstdhneio'ARSTDHNEIO""|zxcvbkm,./ZXCVBKM<>? "
 "workman""`1234567890-=~!@#$%^&*()_+qdrwbjfup;[]QDRWBJFUP:{}ashtgyneoi'ASHTGYNEOI""|zxmcvkl,./ZXMCVKL<>? "


# 2-modifier: source keymap as 𝕗 and target as 𝕘, file contents 𝕩
files  
  "inputrc"{
    m  𝕗 Map('"'=,"\"¨) 𝕘
    {
      cd  ¯6¯2
      ((=´cd)¨𝕩) (c(d))¨ M _sl_ 3¯5 𝕩
    }(9)
  }
  "XCompose"{
    xc  Map´ cl  (¨1¨) (¯1+`<'a''z'<) "`grave-minus=equal~asciitilde!exclam@at#numbersign$dollar%percent^circumflex&ampersand*asterisk(parenleft)parenright_underscore+plus[bracketleft]bracketright{braceleft}braceright:colon;semicolon""quotedbl,comma.period/slash<less>greater?question space'apostrophe"
    (𝕗 Map{¨XC((𝕩c)/)𝕩} 𝕘) _sl_ 25¯7(4)
  }


_lookup_  {
  optres  <˘⍉>𝕗
  err  "Invalid "𝕘"; options:"" "¨opt
  res ˜ ·(err A ·´(opt)>) opt
}
k      keys  _lookup_ "key layout (-k)"  1key"dvorak"
conv    files _lookup_ "keymap file (-i)" inp
write  •Out¨(0=≠) {(•wdpath•file.At𝕩)•file.Lines}¨out
{𝕊wci: W qwerty _c_ k •file.Lines i}˘ ⍉>writeconvinp