-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
603 lines (532 loc) · 25.7 KB
/
shell.nix
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
#################################################################################################################
# Portable bash shell with all dependencies and scripts to work with QMK. #
# #
# Copyright 2022 Leandro Emmanuel Reina Kiperman <@kip93> #
# #
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General #
# Public License as published by the Free Software Foundation, either version 3 of the License, or (at your #
# option) any later version. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the #
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License #
# for more details. #
# #
# You should have received a copy of the GNU General Public License along with this program. If not, see #
# <http://www.gnu.org/licenses/>. #
#################################################################################################################
{ pkgs ? import <nixpkgs> { }, ... }:
let
#################
# Configuration #
#################
# Name of the folder inside the QMK submodule
# e.g., `ergodox_ez`, `0xcb/1337`, et cetera
KEYBOARD = "crkbd";
# Number of threads to be used when compiling.
PARALLEL = 16;
in
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cacert
git
nix
openssh
];
shellHook = with pkgs; ''
# Bash configs #################################################################
shopt -s histappend
shopt -s cmdhist
shopt -s checkwinsize
shopt -s globstar
shopt -s dotglob
HISTCONTROL=ignoreboth
HISTSIZE=1000
HISTFILESIZE=2000
# Extra bling for some commands ################################################
eval "$(SHELL='${bashInteractive}/bin/bash' '${lesspipe}/bin/lesspipe.sh')"
eval "$('${coreutils}/bin/dircolors' -b)"
# Globals ######################################################################
_ROOT_DIR='${toString ./.}'
# Create a dynamic CLI prompt ##################################################
_compute_prompt() {
# First of all, get the exit code of the command before it is lost.
local XC=$?
local XC_colour="$(
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' 10 ;
elif [ "''${XC}" -lt 128 ] ; then
'${coreutils}/bin/printf' 9 ;
else
'${coreutils}/bin/printf' 11 ;
fi ;
)"
local XC_PS1="\[\033[38;5;''${XC_colour}m\]$('${coreutils}/bin/printf' '0x%02X' "''${XC}")\[\033[1m\]\[$('${ncurses}/bin/tput' sgr0)\]"
# Compute the path relative to the root of the project (or absolute path if outside of said folder).
local path="$(
'${coreutils}/bin/realpath' -m --relative-to="''${_ROOT_DIR}" "$('${coreutils}/bin/pwd')"
)/"
[[ "''${path}" =~ ^\.\..+$ ]] && path="$('${coreutils}/bin/pwd')"
[[ "''${path}" =~ ^/.+$|^\./$ ]] || path="./''${path}"
local path_PS1="\[\033[1;38;5;12m\]''${path}\[$('${ncurses}/bin/tput' sgr0)\]"
# Check the branch of the repo and its status.
local is_git="$(
'${git}/bin/git' -C "''${_ROOT_DIR}" rev-parse --git-dir >/dev/null 2>&1 &&
[ "$('${git}/bin/git' -C "''${_ROOT_DIR}" rev-parse --show-toplevel)" -ef "''${_ROOT_DIR}" ] &&
'${coreutils}/bin/printf' true ;
)"
local git_status="$(
[ ! -z "''${is_git}" ] &&
'${git}/bin/git' -C "''${_ROOT_DIR}" status --porcelain ;
)"
local ref="$(
if [ ! -z "''${is_git}" ] ; then
'${git}/bin/git' -C "''${_ROOT_DIR}" rev-parse --abbrev-ref HEAD 2>/dev/null || true ;
else
'${coreutils}/bin/printf' '<N/A>' ;
fi ;
)"
[ "''${ref}" = "HEAD" ] && ref="$(
'${git}/bin/git' -C "''${_ROOT_DIR}" rev-parse --short HEAD 2>/dev/null ||
'${git}/bin/git' -C "''${_ROOT_DIR}" branch --show-current ;
)"
local ref_colour="$(
if [ -z "''${is_git}" ] ; then
'${coreutils}/bin/printf' 9 ;
elif [ \
"$(
'${coreutils}/bin/printf' '%s\n' "''${git_status}" |
'${gnused}/bin/sed' '/^\s*$/d' |
'${coreutils}/bin/wc' -l ;
)" -eq 0 \
] ; then
'${coreutils}/bin/printf' 10 ;
elif
'${coreutils}/bin/printf' '%s\n' "''${git_status}" |
'${gnugrep}/bin/grep' -q '^.\S' ; then
'${coreutils}/bin/printf' 9 ;
else
'${coreutils}/bin/printf' 11 ;
fi ;
)"
local ref_PS1="\[\033[1;38;5;''${ref_colour}m\]$ref\[$('${ncurses}/bin/tput' sgr0)\]"
# Nix shell hint.
local nix_PS1='\[\033[1;38;5;13m\]NIX+QMK\[$('${ncurses}/bin/tput' sgr0)\]'
# Colour CLI prompt.
PS1="\[$('${ncurses}/bin/tput' sgr0)\][ ''${nix_PS1} @ ''${ref_PS1} : ''${path_PS1} ] ''${XC_PS1} > \[$('${ncurses}/bin/tput' sgr0)\]"
return "''${XC}" # Restore the original exit code
}
PROMPT_COMMAND=_compute_prompt
# Aliases ######################################################################
alias ls="'${coreutils}/bin/ls' --color=auto"
alias ll="'${coreutils}/bin/ls' --color=auto -lAh"
# Commands #####################################################################
init() {
local XC=0
(
'${git}/bin/git' -C "''${_ROOT_DIR}" rev-parse --git-dir >/dev/null 2>&1 && \
[ "$('${git}/bin/git' -C "''${_ROOT_DIR}" rev-parse --show-toplevel)" -ef "''${_ROOT_DIR}" ] ;
) || (
'${coreutils}/bin/printf' \
'# \033[3mInitialise repo\033[0m ------------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}" init -b main
) || XC="$(( "''${XC}" + 0x01 ))" ;
'${coreutils}/bin/printf' '\n' ;
)
[ -d "''${_ROOT_DIR}/QMK/" ] && (
'${coreutils}/bin/printf' \
'# \033[3mClean up submodule\033[0m ---------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/rm' -rf -- "''${_ROOT_DIR}/QMK/" &&
'${coreutils}/bin/printf' "Submodule path 'QMK': deleted\n" ;
) || XC="$(( "''${XC}" + 0x02 ))" ;
'${coreutils}/bin/printf' '\n' ;
)
(
'${git}/bin/git' -C "''${_ROOT_DIR}" config --file .gitmodules --get-regexp path |
'${gawk}/bin/awk' '{ print $2 }' |
'${gnugrep}/bin/grep' -q '^QMK$' ;
) || (
'${coreutils}/bin/printf' \
'# \033[3mAdd QMK submodule\033[0m ----------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}" submodule add --branch master -- 'https://github.com/qmk/qmk_firmware/' QMK ;
) || XC="$(( "''${XC}" + 0x04 ))" ;
'${coreutils}/bin/printf' '\n' ;
)
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' \
'# \033[3mInit submodule\033[0m -------------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}" submodule update --init --recursive --progress ;
) || XC="$(( "''${XC}" + 0x08 ))" ;
'${coreutils}/bin/printf' '\n' ;
fi
'${coreutils}/bin/printf' \
'# \033[3mClean up workspace\033[0m ---------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/rm' -rf -- "''${_ROOT_DIR}/keymap/" ;
) || XC="$(( "''${XC}" + 0x10 ))" ;
'${coreutils}/bin/printf' '\n' ;
'${coreutils}/bin/printf' \
'# \033[3mCopy default keymap\033[0m --------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/cp' -rf -- "''${_ROOT_DIR}/QMK/keyboards/${KEYBOARD}/keymaps/default" "''${_ROOT_DIR}/keymap" ;
) || XC="$(( "''${XC}" + 0x20 ))" ;
'${coreutils}/bin/printf' '\n' ;
return "''${XC}"
}
setup() {
local XC=0
'${coreutils}/bin/printf' \
'# \033[3mSet up udev rules\033[0m ----------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/printf' 'Set up /etc/udev/rules.d/\n' &&
$(
(${which}/bin/which doas >/dev/null 2>/dev/null && ${coreutils}/bin/printf 'doas bash') ||
(${which}/bin/which sudo >/dev/null 2>/dev/null && ${coreutils}/bin/printf 'sudo bash') ||
(${coreutils}/bin/printf 'su')
) -c "
'${coreutils}/bin/mkdir' -p '/etc/udev/rules.d/' &&
'${coreutils}/bin/cp' -rf \"''${_ROOT_DIR}/QMK/util/udev/\"* '/etc/udev/rules.d/'
" &&
'${coreutils}/bin/printf' '/etc/udev/rules.d/ set up successfully\n' ;
) || XC="$(( "''${XC}" + 0x01 ))" ;
'${coreutils}/bin/printf' '\n' ;
'${coreutils}/bin/printf' \
'# \033[3mResize /run/user/$UID\033[0m ------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/printf' 'Set up /etc/udev/rules.d/\n' &&
$(
(${which}/bin/which doas >/dev/null 2>/dev/null && ${coreutils}/bin/printf 'doas sh') ||
(${which}/bin/which sudo >/dev/null 2>/dev/null && ${coreutils}/bin/printf 'sudo sh') ||
(${coreutils}/bin/printf 'su')
) -c "
'${coreutils}/bin/mkdir' -p '/etc/systemd/logind.conf.d/' &&
'${coreutils}/bin/printf' '[Login]\nRuntimeDirectorySize=99%%\n' >'/etc/systemd/logind.conf.d/runtime_directory_size.conf'
" &&
'${coreutils}/bin/printf' '/run/user/$UID resized successfully\n' ;
) || XC="$(( "''${XC}" + 0x02 ))" ;
'${coreutils}/bin/printf' '\n' ;
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' \
'# \033[3mFinish\033[0m ---------------------------------------------------------------------------------------------- #\n' ;
'${coreutils}/bin/printf' '\033[3mSet up complete.\nPlease reboot your system to ensure that changes take effect.\033[0m\n\n'
fi
return "''${XC}"
}
update() {
local XC=0
'${coreutils}/bin/printf' \
'# \033[3mUpdate submodules\033[0m ----------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}" submodule update --remote --progress ;
) || XC="$(( "''${XC}" + 0x01 ))" ;
'${coreutils}/bin/printf' '\n' ;
return "''${XC}"
}
clean() {
local XC=0
'${coreutils}/bin/printf' \
'# \033[3mClean workspace\033[0m ------------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}/QMK" clean -df &&
'${git}/bin/git' -C "''${_ROOT_DIR}" clean -dfX ;
) || XC="$(( "''${XC}" + 0x01 ))" ;
'${coreutils}/bin/printf' '\n' ;
return "''${XC}"
}
lint() {
local XC=0
local KEYMAP_ID="$('${coreutils}/bin/cat' /proc/sys/kernel/random/uuid)"
'${coreutils}/bin/printf' \
'# \033[3mLink keymap\033[0m ----------------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/rm' -f -- "''${_ROOT_DIR}"/'QMK/keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" &&
'${coreutils}/bin/ln' -sf "''${_ROOT_DIR}/keymap" "''${_ROOT_DIR}"/'QMK/keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" &&
'${coreutils}/bin/printf' 'Linked QMK/keyboards/${KEYBOARD}/keymaps/%s\n' "''${KEYMAP_ID}" ;
) || XC="$(( "''${XC}" + 0x01 ))" ;
'${coreutils}/bin/printf' '\n' ;
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' \
'# \033[3mQMK linting\033[0m ----------------------------------------------------------------------------------------- #\n' ;
(
cd "''${_ROOT_DIR}/QMK" &&
'${nix}/bin/nix-shell' --pure --run "qmk lint --strict -kb '${KEYBOARD}' -km ''\'''${KEYMAP_ID}'" ;
) || XC="$(( "''${XC}" + 0x02 ))" ;
'${coreutils}/bin/printf' '\n' ;
fi
'${coreutils}/bin/printf' \
'# \033[3mUnlink keymap\033[0m --------------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}/QMK" clean -df ;
) || XC="$(( "''${XC}" + 0x04 ))" ;
'${coreutils}/bin/printf' '\n' ;
return "''${XC}"
}
format() {
local XC=0
local KEYMAP_ID="$('${coreutils}/bin/cat' /proc/sys/kernel/random/uuid)"
'${coreutils}/bin/printf' \
'# \033[3mLink keymap\033[0m ----------------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/rm' -f -- "''${_ROOT_DIR}"/'QMK/keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" &&
'${coreutils}/bin/ln' -sf "''${_ROOT_DIR}/keymap" "''${_ROOT_DIR}"/'QMK/keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" &&
'${coreutils}/bin/printf' 'Linked QMK/keyboards/${KEYBOARD}/keymaps/%s\n' "''${KEYMAP_ID}" ;
) || XC="$(( "''${XC}" + 0x01 ))" ;
'${coreutils}/bin/printf' '\n' ;
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' \
'# \033[3mFormat code\033[0m ----------------------------------------------------------------------------------------- #\n' ;
(
cd "''${_ROOT_DIR}/QMK" &&
'${nix}/bin/nix-shell' --pure --run "${clang-tools}/bin/clang-format -i --verbose \$(
${findutils}/bin/find -L 'keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" -type f -regextype awk -regex '.+\.(h|hpp|c|cpp|inc)'
)" ;
) || XC="$(( "''${XC}" + 0x02 ))" ;
'${coreutils}/bin/printf' '\n' ;
fi
'${coreutils}/bin/printf' \
'# \033[3mUnlink keymap\033[0m --------------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}/QMK" clean -df ;
) || XC="$(( "''${XC}" + 0x04 ))" ;
'${coreutils}/bin/printf' '\n' ;
return "''${XC}"
}
compile() {
local XC=0
local KEYMAP_ID="$('${coreutils}/bin/cat' /proc/sys/kernel/random/uuid)"
'${coreutils}/bin/printf' \
'# \033[3mClean up old builds\033[0m --------------------------------------------------------------------------------- #\n' ;
(
cd "''${_ROOT_DIR}/QMK" &&
'${nix}/bin/nix-shell' --pure --run 'qmk clean' &&
'${coreutils}/bin/printf' 'Cleaned QMK/.build\n' ;
) || XC="$(( "''${XC}" + 0x01 ))" ;
'${coreutils}/bin/printf' '\n' ;
'${coreutils}/bin/printf' \
'# \033[3mLink keymap\033[0m ----------------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/rm' -f -- "''${_ROOT_DIR}"/'QMK/keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" &&
'${coreutils}/bin/ln' -sf "''${_ROOT_DIR}/keymap" "''${_ROOT_DIR}"/'QMK/keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" &&
'${coreutils}/bin/printf' 'Linked QMK/keyboards/${KEYBOARD}/keymaps/%s\n' "''${KEYMAP_ID}" ;
) || XC="$(( "''${XC}" + 0x02 ))" ;
'${coreutils}/bin/printf' '\n' ;
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' \
'# \033[3mCompile\033[0m --------------------------------------------------------------------------------------------- #\n' ;
(
cd "''${_ROOT_DIR}/QMK" &&
'${nix}/bin/nix-shell' --pure --run "qmk compile -j '${builtins.toString PARALLEL}' -kb '${KEYBOARD}' -km ''\'''${KEYMAP_ID}'" ;
) || XC="$(( "''${XC}" + 0x04 ))" ;
'${coreutils}/bin/printf' '\n' ;
fi
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' \
'# \033[3mExtract HEX file\033[0m ------------------------------------------------------------------------------------ #\n' ;
(
'${coreutils}/bin/mkdir' -p "''${_ROOT_DIR}/.build" &&
'${coreutils}/bin/ls' "''${_ROOT_DIR}/QMK/.build"/*.hex |
'${coreutils}/bin/head' -1 |
'${findutils}/bin/xargs' -i cp -f -- '{}' "''${_ROOT_DIR}/.build/firmware.hex" &&
'${coreutils}/bin/printf' 'Extracted .build/firmware.hex\n' ;
) || XC="$(( "''${XC}" + 0x08 ))" ;
'${coreutils}/bin/printf' '\n'
fi
'${coreutils}/bin/printf' \
'# \033[3mUnlink keymap\033[0m --------------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}/QMK" clean -df ;
) || XC="$(( "''${XC}" + 0x10 ))" ;
'${coreutils}/bin/printf' '\n' ;
return "''${XC}"
}
flash() {
local XC=0
local KEYMAP_ID="$('${coreutils}/bin/cat' /proc/sys/kernel/random/uuid)"
'${coreutils}/bin/printf' \
'# \033[3mClean up old builds\033[0m --------------------------------------------------------------------------------- #\n' ;
(
cd "''${_ROOT_DIR}/QMK" &&
'${nix}/bin/nix-shell' --pure --run 'qmk clean' &&
'${coreutils}/bin/printf' 'Cleaned QMK/.build\n' ;
) || XC="$(( "''${XC}" + 0x01 ))" ;
'${coreutils}/bin/printf' '\n' ;
'${coreutils}/bin/printf' \
'# \033[3mLink keymap\033[0m ----------------------------------------------------------------------------------------- #\n' ;
(
'${coreutils}/bin/rm' -f -- "''${_ROOT_DIR}"/'QMK/keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" &&
'${coreutils}/bin/ln' -sf "''${_ROOT_DIR}/keymap" "''${_ROOT_DIR}"/'QMK/keyboards/${KEYBOARD}/keymaps'/"''${KEYMAP_ID}" &&
'${coreutils}/bin/printf' 'Linked QMK/keyboards/${KEYBOARD}/keymaps/%s\n' "''${KEYMAP_ID}" ;
) || XC="$(( "''${XC}" + 0x02 ))" ;
'${coreutils}/bin/printf' '\n' ;
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' \
'# \033[3mCompile\033[0m --------------------------------------------------------------------------------------------- #\n' ;
(
cd "''${_ROOT_DIR}/QMK" &&
'${nix}/bin/nix-shell' --pure --run "qmk compile -j '${builtins.toString PARALLEL}' -kb '${KEYBOARD}' -km ''\'''${KEYMAP_ID}'" ;
) || XC="$(( "''${XC}" + 0x04 ))" ;
'${coreutils}/bin/printf' '\n' ;
fi
if [ "''${XC}" -eq 0 ] ; then
'${coreutils}/bin/printf' \
'# \033[3mFlash\033[0m ----------------------------------------------------------------------------------------------- #\n' ;
(
cd "''${_ROOT_DIR}/QMK" &&
'${nix}/bin/nix-shell' --pure --run "qmk flash -j '${builtins.toString PARALLEL}' -kb '${KEYBOARD}' -km ''\'''${KEYMAP_ID}'" ;
) || XC="$(( "''${XC}" + 0x08 ))" ;
'${coreutils}/bin/printf' '\n' ;
fi
'${coreutils}/bin/printf' \
'# \033[3mUnlink keymap\033[0m --------------------------------------------------------------------------------------- #\n' ;
(
'${git}/bin/git' -C "''${_ROOT_DIR}/QMK" clean -df ;
) || XC="$(( "''${XC}" + 0x10 ))" ;
'${coreutils}/bin/printf' '\n' ;
return "''${XC}"
}
help() {
'${coreutils}/bin/cat' <<EOF | MANPAGER="''${MANPAGER:-''${PAGER:-${most}/bin/most -s}}" '${man}/bin/man' -l - 2>/dev/null
.TH "NIX+QMK" "1" "" "" "Nix+QMK toolbox"
.\----------------------------------------------------------------------------\.
.SH NAME
.IP clean .9i
- Clean workdir.
.IP compile
- Build the keymap into a flashable .hex file.
.IP flash
- Burn the firmware onto a keyboard.
.IP format
- Formats the keymap code.
.IP help
- Show help info on available commands.
.IP init
- Setup your workspace.
.IP lint
- Run a simple lint on the keymap source code.
.IP setup
- Configure the work environment.
.IP update
- Update QMK to latest version.
.IP welcome
- Show the welcome screen.
.\----------------------------------------------------------------------------\.
.SH DESCRIPTION
Set of scripts to handle out of tree QMK keymaps. The intended purpose of these
is to both decluter QMK itself and to allow versioning of QMK to mitigate the
effects of breaking changes.
.PP
NOTE: None of these commands take any arguments.
.\----------------------------------------------------------------------------\.
.SH EXAMPLES
Usual development goes something along the lines:
.PP
.nf
.RS
# Install Nix
sh <(curl -L 'https://nixos.org/nix/install') --no-daemon
# Clone keymap repo
# If you don't clone, an empty repo will be initialised later on
git clone 'https://github.com/<USER>/<REPO>/' '<WORKDIR>'
cd '<WORKDIR>'
# Enter Nix+QMK toolbox
nix-shell
# Initialise your workspace, including a default keymap
init
# Set up environment
setup
# Reboot to make environment setup changes take effect
sudo reboot now
# After reboot, move back to workdir
cd '<WORKDIR>'
# Enter back into Nix+QMK toolbox
nix-shell
# Edit the keymap
vim ./keymap/keymap.c
# Format code
format
# Check code
lint
# Once done editing, compile the code
compile
# After the code compiled successfully, flash it
# (Put the keyboard into bootloader mode when prompted)
flash
# Clean up build files
clean
# When there is an update to QMK
update
# You may need to set up the environment again
setup
# Reboot to make setup changes take effect
sudo reboot now
.RE
.fi
.\----------------------------------------------------------------------------\.
.SH PROMPT EXPLAINED
The CLI tool has a custom prompt, which shows some non essential but nice to
have info.
.PP
.nf
+-------------------------- A simple hardcoded value, to serve as a
| hint that we are currently inside the
| toolbox environment.
|
| +------------------ The current ref of the repo. May be a
| | branch name, a commit hash, or <N/A>,
| | depending of the current status of the
| | repo (or lack thereof). It also sports
| | a colour code:
| | * Green for clean repos.
| | * Yellow for a repo with staged but
| | uncommitted changes.
| | * Red if there are unstaged changes.
| |
| | +---------- The current directory, relative to the
| | | root of the project.
| | |
| | | +-- The exit code of the last command,
| | | | formatted in HEX and colour coded.
| | | | * Green for success (0x00).
| | | | * Red for errors (0x01-0x7F).
| | | | * Yellow for signals (0x80-0xFF).
V V V V
[ NIX+QMK @ main : ./foo/ ] 0x00 >
.fi
.\----------------------------------------------------------------------------\.
.SH TROUBLESHOOTING
If something is not working as expected, the first step to check is the exit
code itself. I've wrote the scripts in such a way that each bit in the exit code
corresponds to a specific section of said script. e.g., if the code is 5, then
the sections 1 and 3 failed ( 2^(1-1) + 2^(3-1) = 5 ).
.PP
From the exit code you may be able to inspect the shell.nix file to determine
the source of the issue (the entirety of the relevant code is in there in a
monolithic file).
.PP
If you want to open an issue or a PR feel free to do so @
.br
https://github.com/kip93/qmk-crkbd/
EOF
return 0
}
welcome() {
'${coreutils}/bin/printf' '\033[0m , , , , , ,\n'
'${coreutils}/bin/printf' '\033[0m \033[1;30m.-------------.\033[0m\n'
'${coreutils}/bin/printf' '\033[0m - \033[1;30m| | \033[0m- \033[3mWelcome to this (unofficial) \033[1mNix+QMK toolbox\033[0;3m.\033[0m\n'
'${coreutils}/bin/printf' '\033[0m - \033[1;30m| \033[0;1m| | |\033[0;1;30m | \033[0m-\n'
'${coreutils}/bin/printf' '\033[0m - \033[1;30m| \033[0;1m| | |\033[0;1;30m | \033[0m- \033[3mAn opinionated set of scripts for standalone QMK keymaps\033[0m\n'
'${coreutils}/bin/printf' '\033[0m - \033[1;30m| \033[0;1m|__|__|\033[0;1;30m | \033[0m-\n'
'${coreutils}/bin/printf' '\033[0m - \033[1;30m| \033[0;1m|\033[0;1;30m | \033[0m-\n'
'${coreutils}/bin/printf' '\033[0m - \033[1;30m|_____________| \033[0m-\n'
'${coreutils}/bin/printf' '\033[0m , , , , , ,\n'
'${coreutils}/bin/printf' '\n'
'${coreutils}/bin/printf' '\033[0m\033[3mType `help` to get info on available commands.\033[0m\n'
'${coreutils}/bin/printf' '\n'
return 0
}
[[ $- != *i* ]] || welcome
'';
}