-
Notifications
You must be signed in to change notification settings - Fork 27
/
profile_any.mx
820 lines (707 loc) · 20 KB
/
profile_any.mx
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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
alias help=murex-docs
autocomplete set murex-docs %[ {
FlagsDesc: {
--docs: "Returns a JSON object of every document available to read offline"
--summary: "Returns an abridged description of the command rather than the entire help page"
}
DynamicDesc: '{ fexec builtin murex-docs --docs }'
FlagValues: {
--summary: [{
Dynamic: '{ fexec builtin murex-docs --docs }'
}]
}
ListView: true
} ]
autocomplete set help autocomplete(get murex-docs)
alias builtin=fexec builtin
alias command=exec
alias echo=out
method define echo %{
Stdin: null
Stdout: str
}
config eval shell safe-commands {
-> alter --merge / %[ echo ]
}
private autocomplete.test.run-unit {
# Returns all available tests for `test run`
runtime: --tests -> [ unit ] -> foreach: test {
out: $test[function]
} -> cast str -> prepend *
}
test unit private autocomplete.test.run-unit %{
StdoutRegex: '^(([-_./a-zA-Z0-9]+|\*)\n)+'
StdoutType: str
StdoutGreaterThan: 1
StdoutIsArray: true
}
autocomplete set test %[
{
FlagsDesc: {
config: "Enable or disable boolean test states (more options available in `config test ...`)"
define: "Define an inlined test"
state: "Define a state report"
run: "Execute a code block, function or unit test with inline testing enabled"
unit: "Define a unit test"
report: "Write the test report (happens automatically by default)"
}
FlagValues: {
config: [{
FlagsDesc: {
enable: "Enable inlined tests"
!enable: "Disable inlined tests"
auto-report: "Automatically output report (default)"
!auto-report: "Do not automatically output report"
verbose: "Verbose report"
!verbose: "Concise report (default)"
}
AllowMultiple: true
Optional: false
}]
run: [{
Dynamic: '{ autocomplete.test.run-unit }'
}]
}
}
]
function h {
# Output the murex history log in a human readable format
history \
-> foreach {
-> set json line
out "$line[Index]: $line[Block]"
} \
-> cast *
}
function aliases {
# Output the aliases in human readable format
cast str
runtime --aliases \
-> formap k v {
out "$k => ${esccli @v.Alias}"
} \
-> sort
}
test unit function aliases %{
PreBlock: '{
alias ALIAS_UNIT_TEST=example param1 param2 param3
}'
PostBlock: '{
!alias ALIAS_UNIT_TEST
}'
StdoutRegex: '([- _0-9a-zA-Z]+ => .*?\n)+'
StdoutType: str
}
autocomplete set exec %[
{
IncFiles: true
IncDirs: true
IncExePath: true
}
{
NestedCommand: true
}
]
autocomplete set format %[{
Dynamic: '{ runtime --marshallers }'
}]
private autocomplete.data-types {
# Returns all murex data-types compiled
cast str
runtime --readarray -> format str
runtime --readarraywithtype -> format str
runtime --writearray -> format str
runtime --readmap -> format str
runtime --marshallers -> format str
runtime --unmarshallers -> format str
}
test unit private autocomplete.data-types %{
StdoutRegex: '^(([a-z0-9]+|\*)\n)+'
StdoutType: str
StdoutGreaterThan: 1
StdoutIsArray: true
}
autocomplete set cast %[{
Dynamic: '{ autocomplete.data-types }'
}]
autocomplete set tout %[{
Dynamic: '{ autocomplete.data-types }'
}]
private autocomplete.variables.locals {
# Returns all local variable names
cast str
runtime --variables -> formap k v { out $k }
}
private autocomplete.variables.globals {
# Returns all global variable names
cast str
runtime --globals -> formap k v { out $k }
}
private autocomplete.variables {
# Returns all global and local variable names
cast str
autocomplete.variables.locals
autocomplete.variables.globals
}
test unit private autocomplete.variables %{
PreBlock: '{
GLOBAL.MUREX_UNIT_TEST = "foobar"
}'
PostBlock: '{
!global MUREX_UNIT_TEST
}'
StdoutRegex: '([_a-zA-Z0-9]+\n)+'
StdoutType: str
StdoutGreaterThan: 1
StdoutIsArray: true
}
autocomplete: set set %[{
Dynamic: '{ autocomplete.variables.locals }'
AnyValue: true
}]
autocomplete: set !set %[{
Dynamic: '{ autocomplete.variables.locals }'
}]
autocomplete set global %[{
Dynamic: '{ autocomplete.variables.globals }'
AnyValue: true
}]
autocomplete set !global %[{
Dynamic: '{ autocomplete.variables.globals }'
}]
autocomplete set export %[
{
Dynamic: '{ autocomplete.variables }'
AnyValue: true
}
{
IncDirs: true
}
]
autocomplete set !export %[{
DynamicDesc: '{ runtime --exports }'
}]
autocomplete set unset %[{
DynamicDesc: '{ runtime --exports }'
}]
private autocomplete.pipe-types {
# Returns CLI flags for pipe
runtime --pipes \
-> !match std \
-> prefix "--"
}
test unit private autocomplete.pipe-types %{
StdoutRegex: "--file"
}
autocomplete set pipe %[
{
AnyValue: true
}
{
Dynamic: '{ autocomplete.pipe-types }'
FlagValues: {
--file: [{ IncFiles: true }]
}
}
]
private autocomplete.!pipe-list {
# Returns CLI flags for ` + "`!pipe`" + `
runtime: --named-pipes -> ![ null ]
}
test unit private autocomplete.!pipe-list %{
PreBlock: '{ pipe autocompleteunittest }'
PostBlock: '{ !pipe autocompleteunittest }'
StdoutRegex: "autocompleteunittest"
}
autocomplete set !pipe %[{
DynamicDesc: '{ autocomplete.!pipe-list }'
AllowMultiple: true
}]
private autocomplete.index {
switch ${ get-type stdin } {
case * {
<stdin> \
-> [ 0: ] \
-> format json \
-> [ 0 ] \
-> append "]"
}
case csv {
<stdin> \
-> [ 0: ] \
-> format json \
-> [ 0 ] \
-> append "]"
}
case jsonl {
<stdin> \
-> [ 0 ] \
-> set header
$header \
-> cast utf8 \
-> [ 0 -1 ] \
-> set jsonl_format
if { $jsonl_format == "[]" } then {
tout json $header \
-> append "]"
}
}
catch {
<stdin> \
-> formap k v { out $k } \
-> cast str \
-> append "]" \
-> format json
}
}
}
autocomplete set "[" %[{
AnyValue: true
AllowMultiple: true
ExecCmdline: true
Dynamic: '{ autocomplete.index }'
}]
autocomplete: set "[[" %[{
AnyValue: true
ExecCmdline: true
AutoBranch: true
Dynamic: '{ -> struct-keys -> append "]]" }'
}]
private autocomplete.config.get.apps {
# Returns all app names for the 'app' field in `config`
config: -> formap k v { out $k } -> cast: str -> msort
}
test unit private autocomplete.config.get.apps %{
StdoutRegex: "shell"
StdoutType: str
StdoutGreaterThan: 1
StdoutIsArray: true
}
private autocomplete.config.get.keys {
# Returns all keys for the 'app' field in `config`
config \
-> [ $PARAMS[0] ] \
-> formap k v { out $k } \
-> cast str
}
test unit private autocomplete.config.get.keys %{
Parameters: [ shell ]
StdoutRegex: prompt
StdoutType: str
StdoutGreaterThan: 1
StdoutIsArray: true
}
autocomplete: set config %[{
Flags: [ get set eval define default ]
FlagValues: {
get: [
{ Dynamic: '{ autocomplete.config.get.apps }' }
{ Dynamic: '{ autocomplete.config.get.keys $PARAMS[1] }' }
],
set: [
{ Dynamic: '{ autocomplete.config.get.apps }' }
{ Dynamic: '{ autocomplete.config.get.keys $PARAMS[1] }' }
{ Dynamic: '{
switch {
case { ${ config -> [[ /$PARAMS[1]/$PARAMS[2]/Data-Type ]] } == "bool" } {
%[true false]
}
case { config -> [ $PARAMS[1] ] -> [ $PARAMS[2] ] -> [ <!null> Options ] } {
config -> [[ /$PARAMS[1]/$PARAMS[2]/Options ]]
}
catch {
config -> [[ /$PARAMS[1]/$PARAMS[2]/Default ]]
}
}
}' }
]
eval: [
{ Dynamic: '{ autocomplete.config.get.apps }' }
{ Dynamic: '{ autocomplete.config.get.keys $PARAMS[1] }' }
],
default: [
{ Dynamic: '{ autocomplete.config.get.apps }' }
{ Dynamic: '{ autocomplete.config.get.keys $PARAMS[1] }' }
]
}
}]
autocomplete set test-autocomplete %[{
Flags: [ "111", "222", "333", "444" ]
FlagValues: {
"111": [
{ Dynamic: %({ out aaa\nbbb\nccc\n$PARAMS }) }
{ Dynamic: %({ out ddd\neee\nfff\n$PARAMS }) }
],
"222": [
{ Dynamic: %({ out ggg\nhhh\niii\n$PARAMS }) }
{ Dynamic: %({ out jjj\nkkk\nlll\n$PARAMS }) }
],
"333": [
{ Dynamic: %({ out mmm\nnnn\nooo\n$PARAMS }) }
{ Dynamic: %({ out ppp\nqqq\nrrr\n$PARAMS }) }
],
"444": [
{ Dynamic: %({ out sss\nttt\nuuu\n$PARAMS }) }
{ Dynamic: %({ out vvv\nwww\nxxx\n$PARAMS }) }
]
}
}]
autocomplete set !config %[
{ Dynamic: '{ autocomplete.config.get.apps }' }
{ Dynamic: '{ autocomplete.config.get.keys $PARAMS[0] }' }
]
autocomplete set event %[{
Dynamic: '{
runtime --events \
-> formap k v { out $k }
}'
}]
autocomplete set !event %[
{
Dynamic: '{
runtime --events \
-> formap k v { out $k } \
-> msort
}'
},
{
Dynamic: '{
runtime: --events \
-> [ $ARGS[1] ] \
-> formap k v { out $k } \
-> msort
}'
}
]
private autocomplete.alias {
# Returns a map of all alises and the code they execute
runtime --aliases \
-> formap --jmap name value { $name } { out @value }
}
test unit private autocomplete.alias %{
StdoutRegex: jobs
StdoutType: json
StdoutGreaterThan: 1
StdoutIsMap: true
}
autocomplete set !alias %[{
DynamicDesc: %({ autocomplete.alias })
ListView: true
}]
private autocomplete.functions {
# Returns a map of all murex public functions
runtime --functions -> formap --jmap k v { $k } { out $v[summary] }
}
test unit private autocomplete.functions %{
PreBlock: %({
function unit.test.autocomplete.functions {
out "This is only a dummy function for testing"
}
})
PostBlock: %({ !function unit.test.autocomplete.functions })
StdoutRegex: unit.test.autocomplete.functions
StdoutType: json
StdoutIsMap: true
StdoutGreaterThan: 1
}
autocomplete set !function %[{
DynamicDesc: %({ autocomplete.functions })
ListView: true
}]
private autocomplete.privates {
# Returns a map of all murex private functions
runtime --privates \
-> struct-keys 3 \
-> regexp m,/.*?/.*?/, \
-> foreach --jmap private { $private } {
runtime --privates \
-> [[ $private/Summary ]]
}
}
test unit private autocomplete.privates %{
StdoutType: json
StdoutGreaterThan: 1
StdoutIsMap: true
}
autocomplete set fexec %[{
DynamicDesc: %({ fexec help })
FlagValues: {
function: [{
DynamicDesc: %({ autocomplete.functions })
ListView: true
}]
private: [{
DynamicDesc: %({ autocomplete.privates })
ListView: true
}]
builtin: [{
DynamicDesc: %({ autocomplete.builtins })
ListView: true
}]
}
}]
private autocomplete.builtins {
# Returns a map of all murex builtins
runtime --builtins \
-> foreach --jmap builtin { $builtin } {
fexec <!null> builtin murex-docs --summary $builtin \
|| fexec builtin murex-docs --summary parser/$builtin
}
}
test unit private autocomplete.builtins %{
StdoutType: json
StdoutGreaterThan: 1
StdoutIsMap: true
}
autocomplete: set autocomplete %[{
Flags: [ get set ]
FlagValues: {
get: [{
Dynamic: '{
runtime --autocomplete \
-> formap cmd ! { out $cmd } \
-> cast str
}'
}]
}
}]
autocomplete: set debug %[{
Flags: [ on off ]
}]
autocomplete: set murex-package %[{
FlagsDesc: {
install: "Installs a package from a user defined URI"
remove: "Removes an installed package from disk"
update: "Updates all installed packages"
import: "Import packages described in a backup package DB from user defined URI or local path"
enable: "Enables a previously disabled package or module"
disable: "Disables a previously enabled package or module"
reload: "Reloads all enabled modules"
status: "Returns the version status of locally installed packages"
list: "Returns a list of indexed packages/modules (eg what's enabled or disabled)"
new: "A wizard to help with creating a new package"
git: "Run `git` against a package"
cd: "Changes working directory to a package's install location"
}
FlagValues: {
import: [{
IncFiles: true
}]
remove: [{
"Dynamic": %({ murex-package list packages })
}]
enable: [{
DynamicDesc: %({ murex-package list disabled })
ListView: true
AutoBranch: true
}]
disable: [{
DynamicDesc: %({ murex-package list enabled })
ListView: true
AutoBranch: true
}]
list: [{
Flags: [ enabled, disabled, loaded, not-loaded, packages ]
}]
git: [
{
Dynamic: %({ murex-package list packages })
}
{
ImportCompletion: git
}
]
cd: [{
Dynamic: %({ murex-package list packages })
}]
}
}]
alias builtins=runtime --builtins
private test.alias.builtins {
# Wrapper function around the alias for `builtins` for unit testing
builtins
}
test unit private test.alias.builtins %{
StdoutType: json
StdoutGreaterThan: 1
StdoutIsArray: true
}
private autocomplete.aliases.and.builtins {
# Returns a list of aliases and builtins
cast str
runtime --aliases -> formap k ! { out $k } -> cast str
builtins -> format str
}
test unit private autocomplete.aliases.and.builtins %{
StdoutType: str
StdoutGreaterThan: 1
StdoutIsArray: true
}
autocomplete set summary %[{
IncExePath: true
Dynamic: %({ autocomplete.aliases.and.builtins })
}]
config eval shell safe-commands {
-> alter --merge / %[ builtins jobs ]
}
function sprintf {
# This is a wrapper around the OS's default `printf`, replacing the now deprecated builtin of the same name
-> set params
switch {
case { $params -> ! } { err "No parameters passed via STDIN" }
case { $ARGS[1]-> ! } { err "No string supplied to print" }
catch {
printf "$ARGS[1]\n" @params
}
}
}
summary docgen "Document generator for murex development"
autocomplete set docgen %[
{
AllowMultiple: true
Optional: true
FlagsDesc: {
-panic: "Write a stack trace on error"
-readonly: "Don't write output to disk. Use this to test the config"
-verbose: "Verbose output (all log messages inc warnings)"
-version: "Output docgen version number and exit"
-warning: "Display warning messages (will also return a non-zero exit status if warnings found)"
}
}
{
FlagsDesc: {
-config: "Location of the base docgen config file"
}
FlagValues: {
-config: [{
IncFiles: true
}]
}
}
]
config define open image %{
Description: "Which mode to render images to the terminal"
DataType: str
Default: auto
Options: [ auto compatible mxtty kitty iterm terminology sixel ]
}
openagent set image {
$ARGS[1] -> set file
config get open image -> set mode
if { = mode==`auto` } {
switch {
case { $TMUX } { set mode=compatible }
case { $MXTTY } { set mode=mxtty }
case { $ITERM_PROFILE } { set mode=iterm }
case { $TERM_PROGRAM == "iTerm.app" } { set mode=iterm }
case { $KITTY_WINDOW_ID } { set mode=kitty }
case { $TERM == "xterm-kitty" } { set mode=kitty }
case { $TERMINOLOGY } { set mode=terminology }
catch { set mode=compatible }
}
}
# If Kitty but running inside a screen / tmux session, fallback to compatible.
# We do this because tmux doesn't support reporting screen sizes via the TIOCGWINSZ ioctl.
if { and { = mode==`kitty` } { = TERM==`screen` } } {
set mode=compatible
}
switch $mode {
case compatible {
open-image $file
}
case mxtty {
if { $SSH_TTY } {
$json = %{ Base64: ${base64 -i $file -o -} }
} else {
$json = %{ Filename: $file }
}
out "{ESC}_insert;image;$(json){ESC}\\"
}
case kitty {
try {
kitty icat $file
}
catch {
err "Error running `kitty`. Please check `kitty` is installed."
}
}
case iterm {
if { $TERM =~ '^(screen|tmux)' } then {
if { ${tmux show -gw allow-passthrough} == "allow-passthrough on" } then {
osc = '{ESC}Ptmux;{ESC}{ESC}]'
st = '{BELL}{ESC}\'
} else {
open-image $file
break switch
}
} else {
osc = '{ESC}]'
st = '{BELL}'
}
out "$(osc)1337;File=inline=1:${base64 -i $file -o -}$(st)"
}
case terminology {
try {
tycat -c $file
}
catch {
err "Error running `tycat`. Please check `terminology` is installed."
}
}
case sixel {
try {
img2sixel $file
}
catch {
err "Error running `img2sixel`. Please check `libsixel` is installed."
}
}
catch {
out "Invalid rendering method. Please define in `config set open image` - 'auto' is recommended."
}
}
}
private autocomplete.openagents {
runtime --open-agents \
-> formap k ! { out $k } \
-> cast str
}
autocomplete set openagent %[{
Flags: [ get, set ]
FlagValues: {
get: [{
Dynamic: %({ autocomplete.openagents })
}]
}
}]
autocomplete set !openagent %[
{
Dynamic: %({ autocomplete.openagents })
}
]
private autocomplete.fid-kill {
# Returns a 2D array FIDs
fid-list --jsonl -> [ FID Command Parameters ]
}
test unit private autocomplete.fid-kill %{
StdoutRegex: %(^\["FID","Command","Parameters"\]\n.*(\["[0-9]+","))
StdoutType: jsonl
ExitNum: 0
StdoutGreaterThan: 1
}
autocomplete: set fid-kill %[{
DynamicDesc: '{ autocomplete.fid-kill }'
ListView: true
AllowMultiple: true
}]
autocomplete set bg %[{
DynamicDesc: '{ fid-list --stopped }'
ListView: true
}]
autocomplete set fg %[{
DynamicDesc: '{
fid-list --background \
-> alter -m / ${ fid-list --stopped }
}'
ListView: true
}]