github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/autocomplete/autocomplete_doc.inc.md (about) 1 The directives are listed below. 2 3 {{ if env "DOCGEN_TARGET=" }}<div id="toc"> 4 5 - [Alias](#alias) 6 - [AllowAny](#allowany) 7 - [AllowMultiple](#allowmultiple) 8 - [AnyValue](#anyvalue) 9 - [AutoBranch](#autobranch) 10 - [CacheTTL](#cachettl) 11 - [Dynamic](#dynamic) 12 - [DynamicDesc](#dynamicdesc) 13 - [DynamicPreview](#dynamicpreview) 14 - [ExecCmdline](#execcmdline) 15 - [FileRegexp](#fileregexp) 16 - [FlagValues](#flagvalues) 17 - [Defaults for matched flags](#defaults-for-matched-flags) 18 - [Defaults for any flags (including unmatched)](#defaults-for-any-flags-including-unmatched) 19 - [Flags](#flags) 20 - [FlagsDesc](#flagsdesc) 21 - [Goto](#goto) 22 - [IgnorePrefix](#ignoreprefix) 23 - [ImportCompletion](#importcompletion) 24 - [IncDirs](#incdirs) 25 - [IncExeAll](#incexeall) 26 - [IncExePath](#incexepath) 27 - [IncFiles](#incfiles) 28 - [IncManPage](#incmanpage) 29 - [ListView](#listview) 30 - [NestedCommand](#nestedcommand) 31 - [Optional](#optional) 32 33 </div> 34 {{ end }} 35 ### Alias 36 37 > Value: `str` (default: empty) 38 39 Aliases are used inside **FlagValues** as a way of pointing one flag to another 40 without duplicating code. eg `-v` and `--version` might be the same flag. Or 41 `-?`, `-h` and `--help`. With **Alias** you can write the definitions for one 42 flag and then point all the synonyms as an alias to that definition. 43 44 ### AllowAny 45 46 > Value: `bool` (default: `false`) 47 48 The way autocompletion works in Murex is the suggestion engine looks for 49 matches and if it fines one, it then moves onto the next index in the JSON 50 schema. This means unexpected values typed in the interactive terminal will 51 break the suggestion engine's ability to predict what the next expected 52 parameter should be. Setting **AllowAny** to `true` tells the suggestion 53 engine to accept any value as the next parameter thus allowing it to then 54 predict the next parameter afterwards. 55 56 This directive isn't usually necessary because such fields are often the last 57 parameter or most parameters can be detectable with a reasonable amount of 58 effort. However **AllowAny** is often required for more complex command line 59 tools. 60 61 ### AllowMultiple 62 63 > Value: `bool` (default: `false`) 64 65 Set to `true` to enable multiple parameters following the same rules as defined 66 in this index. For example the following will suggest directories on each tab 67 for multiple parameters: 68 69 ``` 70 autocomplete set example %[{ 71 IncDirs: true 72 AllowMultiple: true 73 }] 74 ``` 75 76 ### AnyValue 77 78 Deprecated. Please use **AllowAny** instead. 79 80 ### AutoBranch 81 82 > Value `bool` (default: `false`) 83 84 Use this in conjunction with **Dynamic**. If the return is an array of paths, 85 for example `[ "/home/foo", "/home/bar" ]` then **AutoBranch** will return 86 the following patterns in the command line: 87 88 ``` 89 » example [tab] 90 # suggests "/home/" 91 92 » example /home/[tab] 93 # suggests "/home/foo" and "/home/bar" 94 ``` 95 96 Please note that **AutoBranch**'s behavior is also dependant on a "shell" 97 `config` setting, "recursive-enabled": 98 99 ``` 100 » config get shell recursive-enabled 101 true 102 ``` 103 104 ### CacheTTL 105 106 > Value: `int` (default: `5`) 107 108 Dynamic autocompletions (via **Dynamic** or **DynamicDesc**) are cached to 109 improve interactivity performance. By default the cache is very small but you 110 can increase that cache or even disable it entirely. Setting this value will 111 define the duration (in seconds) to cache that autocompletion. 112 113 If you wish to disable this then set **CacheTTL** to `-1`. 114 115 This directive needs to live in the very first definition and affects all 116 autocompletes within the rest of the command. For example 117 118 ``` 119 autocomplete set foobar %[ 120 { 121 Flags: [ --foo, --bar ] 122 CacheTTL: 60 123 } 124 { 125 Dynamic: '{ 126 a [Monday..Friday] 127 sleep 3 128 }' 129 } 130 ] 131 ``` 132 133 Here the days of the week take 3 seconds to show up as autocompletion 134 suggestions the first time and instantly for the next 60 seconds after. 135 136 ### Dynamic 137 138 > Value: code block as a `str` (default: empty) 139 140 This is a Murex block which returns an array of suggestions. 141 142 Code inside that block are executed like a function and the parameters will 143 mirror the same as those parameters entered in the interactive terminal. 144 145 Two variables are created for each **Dynamic** function: 146 147 - `ISMETHOD`: `true` if the command being autocompleted is going to run as a 148 pipelined method. `false` if it isn't. 149 150 - `PREFIX`: contains the partial term. For example if you typed `hello wor[tab]` 151 then `$PREFIX` would be set to **wor** for **hello**'s 152 autocompletion. 153 154 The expected STDOUT should be an array (list) of any data type. For example: 155 156 ``` 157 [ 158 "Monday", 159 "Tuesday", 160 "Wednesday", 161 "Thursday", 162 "Friday" 163 ] 164 ``` 165 166 You can additionally include suggestions if any of the array items exactly 167 matches any of the following strings: 168 169 * `@IncFiles` ([read more](#incfiles-boolean-false)) 170 * `@IncDirs` ([read more](#incdirs-boolean-false)) 171 * `@IncExePath` ([read more](#incexepath-boolean-false)) 172 * `@IncExeAll` ([read more](#incexeall-boolean-false)) 173 * `@IncManPage` ([read more](#incmanpage-boolean-false)) 174 175 ### DynamicDesc 176 177 > Value: code block as a `str` (default: empty) 178 179 This is very similar to **Dynamic** except your function should return a 180 map instead of an array. Where each key is the suggestion and the value is 181 a description. 182 183 The description will appear either in the hint text or alongside the 184 suggestion - depending on which suggestion "popup" you define (see 185 **ListView**). 186 187 Two variables are created for each **Dynamic** function: 188 189 - `ISMETHOD`: `true` if the command being autocompleted is going to run as a 190 pipelined method. `false` if it isn't. 191 192 - `PREFIX`: contains the partial term. For example if you typed `hello wor[tab]` 193 then `$PREFIX` would be set to **wor** for **hello**'s 194 autocompletion. 195 196 The expected STDOUT should be an object (map) of any data type. The key is the 197 autocompletion suggestion, with the value being the description. For example: 198 199 ``` 200 { 201 "Monday": "First day of the week", 202 "Tuesday": "Second day of the week", 203 "Wednesday": "Third day of the week" 204 "Thursday": "Forth day of the week", 205 "Friday": "Fifth day of the week", 206 } 207 ``` 208 209 ### DynamicPreview 210 211 > Value: code block as a `str` (default: empty) 212 213 The **DynamicPreview** directive is used to populate the `[f1]` preview screen. 214 215 STDOUT and STDERR are passed directly to the preview frame. 216 217 ### ExecCmdline 218 219 > Value: `bool` (default: `false`) 220 221 Sometimes you'd want your autocomplete suggestions to aware of the output 222 returned from the commands that preceded it. For example the suggestions 223 for `[` (index) will depend entirely on what data is piped into it. 224 225 **ExecCmdline** tells Murex to run the commandline up until the command 226 which your cursor is editing and pipe that output to the STDIN of that 227 commands **Dynamic** or **DynamicDesc** code block. 228 229 > This is a dangerous feature to enable so **ExecCmdline** is only honoured 230 > if the commandline is considered "safe". **Dynamic** / **DynamicDesc** 231 > will still be executed however if the commandline is "unsafe" then your 232 > dynamic autocompletion blocks will have no STDIN. 233 234 Because this is a dangerous feature, your partial commandline will only 235 execute if the following conditions are met: 236 237 - the commandline must be one pipeline (eg `;` tokens are not allowed) 238 - the commandline must not have any new line characters 239 - there must not be any redirection, including named pipes 240 (eg `cmd <namedpipe>`) and the STDOUT/STDERR switch token (`?`) 241 - the commandline doesn't inline any variables (`$strings`, `@arrays`) or 242 functions (`${subshell}`, `$[index]`) 243 - lastly all commands are whitelisted in "safe-commands" 244 (`config get shell safe-commands`) 245 246 If these criteria are met, the commandline is considered "safe"; if any of 247 those conditions fail then the commandline is considered "unsafe". 248 249 Murex will come with a number of sane commands already included in its 250 `safe-commands` whitelist however you can add or remove them using `config` 251 252 ``` 253 » function foobar { -> match foobar } 254 » config eval shell safe-commands { -> append foobar } 255 ``` 256 257 Remember that **ExecCmdline** is designed to be included with either 258 **Dynamic** or **DynamicDesc** and those code blocks would need to read 259 from STDIN: 260 261 ``` 262 autocomplete set "[" %[{ 263 AnyValue: true 264 AllowMultiple: true 265 ExecCmdline: true 266 Dynamic: '{ 267 switch ${ get-type stdin } { 268 case * { 269 <stdin> -> [ 0: ] -> format json -> [ 0 ] 270 } 271 272 catch { 273 <stdin> -> formap k v { out $k } -> cast str -> append "]" 274 } 275 } 276 }' 277 }] 278 ``` 279 280 ### FileRegexp 281 282 > Value: `str` (default: empty) 283 284 When set in conjunction with **IncFiles**, this directive will filter on files 285 files which match the regexp string. eg to only show ".txt" extensions you can 286 use the following: 287 288 ``` 289 autocomplete set notepad.exe %[{ 290 IncFiles: true 291 FileRegexp: (\.txt) 292 }] 293 ``` 294 295 > Please note that you may need to double escape any regexp strings: escaping 296 > the `.` match and then also escaping the escape character in JSON. It is 297 > recommended you use the `mxjson` method of quoting using parentheses as this 298 > will compile that string into JSON, automatically adding additional escaping 299 > where required. 300 301 ### FlagValues 302 303 > Value: map of arrays (default: empty) 304 305 This is a map of the flags with the values being the same array of directive 306 as the top level. 307 308 This allows you to nest operations by flags. eg when a flag might accept 309 multiple parameters. 310 311 **FlagValues** takes a map of arrays, eg 312 313 ``` 314 autocomplete set example %[{ 315 Flags: [ add, delete ] 316 FlagValues: { 317 add: [{ 318 Flags: [ foo ] 319 }] 320 delete: [{ 321 Flags: [ bar ] 322 }] 323 } 324 }] 325 ``` 326 327 ...will provide "foo" as a suggestion to `example add`, and "bar" as a 328 suggestion to `example delete`. 329 330 #### Defaults for matched flags 331 332 You can set default properties to all matched flags by using `*` as a 333 **FlagValues** value. To expand the above example... 334 335 ``` 336 autocomplete set example %[{ 337 Flags: [ add, delete ] 338 FlagValues: { 339 add: [{ 340 Flags: [ foo ] 341 }] 342 delete: [{ 343 Flags: [ bar ] 344 }] 345 "*": [{ 346 IncFiles 347 }] 348 } 349 }] 350 ``` 351 352 ...in this code we are saying not only does "add" support "foo" and "delete" 353 supports "bar", but both "add" and "delete" also supports any filesystem files. 354 355 This default only applies if there is a matched **Flags** or **FlagValues**. 356 357 #### Defaults for any flags (including unmatched) 358 359 If you wanted a default which applied to all **FlagValues**, even when the flag 360 wasn't matched, then you can use a zero length string (""). For example 361 362 ``` 363 autocomplete set example %[{ 364 Flags: [ add, delete ] 365 FlagValues: { 366 add: [{ 367 Flags: [ foo ] 368 }], 369 delete: [{ 370 Flags: [ bar ] 371 }], 372 "": [{ 373 IncFiles: true 374 }] 375 } 376 }] 377 ``` 378 379 ### Flags 380 381 > Value: array of strings (default is auto-populated from man pages) 382 383 Setting **Flags** is the fastest and easiest way to populate suggestions 384 because it is just an array of strings. eg 385 386 ``` 387 autocomplete set example %[{ 388 Flags: [ foo, bar ] 389 }] 390 ``` 391 392 If a command doesn't **Flags** already defined when you request a completion 393 suggestion but that command does have a man page, then **Flags** will be 394 automatically populated with any flags identified from an a quick parse of 395 the man page. However because man pages are written to be human readable 396 rather than machine parsable, there may not be a 100% success rate with the 397 automatic man page parsing. 398 399 ### FlagsDesc 400 401 > Value: map of strings (default: empty) 402 403 This is the same concept as **Flags** except it is a map with the suggestion 404 as a key and description as a value. This distinction is the same as the 405 difference between **Dynamic** and **DynamicDesc**. 406 407 Please note that currently man page parsing cannot provide a description so 408 only **Flags** get auto-populated. 409 410 ### Goto 411 412 > Value: `str` (default: empty) 413 414 This is a `goto` in programming terms. While "ugly" it does allow for quick and 415 easy structural definitions without resorting to writing the entire 416 autocomplete in code. 417 418 **Goto** takes a string which represents the path to jump to from the top level 419 of that autocomplete definition. The path should look something like: 420 `/int/string/int/string....` where 421 422 - the first character is the separator, 423 424 - the first value is an integer that relates to the index in your autocomplete 425 array, 426 427 - the second value is a string which points to the flag value map (if you 428 defined **FlagValues**), 429 430 - the third value is the integer of the autocomplete array inside that 431 **FlagValues** map, 432 433 - ...and so on as necessary. 434 435 An example of a really simple **Goto**: 436 437 ``` 438 autocomplete set dd %[ 439 { 440 Flags: [ "if=", "of=", "bs=", "iflag=", "oflag=", "count=", "status=" ] 441 FlagValues: { 442 "if": [{ 443 IncFiles: true 444 }] 445 "of": [{ 446 IncFiles: true 447 }] 448 "*": [{ 449 AllowAny: true 450 }] 451 } 452 }, 453 { 454 Goto: "/0" 455 } 456 ] 457 ``` 458 459 **Goto** is given precedence over any other directive. So ensure it's the only 460 directive in it's group. 461 462 ### IgnorePrefix 463 464 > Value: `bool` (default: `false`) 465 466 When set to `true`, this allows **Dynamic** and **DynamicDesc** functions to 467 return every result and not just those that match the partial term (as would 468 normally be the default). 469 470 ### ImportCompletion 471 472 > Value: `str` (default: empty) 473 474 This allows you to import autocompletion config from another command. Similar 475 in purpose to **NestedCommand** except where **NestedCommand** will dynamically 476 select the command name, **ImportCompletion** hardcodes it. For example: 477 478 ``` 479 autocomplete set murex-package %[{ 480 FlagsDesc: { 481 # ...cropped out... 482 git: "Run `git` against a package" 483 } 484 FlagValues: { 485 # ...cropped out... 486 git: [ 487 { 488 # list packages to run `git` against 489 Dynamic: %({ murex-package list packages }) 490 } 491 { 492 # include `git` autocompletions as the next set of parameters 493 ImportCompletion: git 494 } 495 ] 496 } 497 }] 498 ``` 499 500 The above code allows you to type `murex-package git package-name [tab]`, where 501 `[tab]` will be the completions for `git`. 502 503 ### IncDirs 504 505 > Value: `bool` (default: `false`) 506 507 Enable to include directories. 508 509 Not needed if **IncFiles** is set to `true`. 510 511 Behavior of this directive can be altered with `config set shell 512 recursive-enabled` 513 514 ### IncExeAll 515 516 > Value: `bool` (default: `false`) 517 518 Enable this to any executables. Suggestions will include aliases, functions 519 builtins and any executables in `$PATH`. It will not include private functions. 520 521 ### IncExePath 522 523 > Value: `bool` (default: `false`) 524 525 Enable this to include any executables in `$PATH`. Suggestions will not include 526 aliases, functions nor privates. 527 528 ### IncFiles 529 530 > Value: `bool` (default: `true`) 531 532 Include files and directories. This is enabled by default for any commands 533 that don't have autocomplete defined but you will need to manually enable 534 it in any `autocomplete` schemas you create and want files as part of the 535 suggestions. 536 537 If you want to filter files based on file name then you can set a regexp 538 string to match to using **FileRegexp**. 539 540 ### IncManPage 541 542 > Value: `bool` (default: `false`) 543 544 The default behavior for commands with no autocomplete defined is to parse the 545 man page and use those results. If a custom autocomplete is defined then that 546 man page parser is disabled by default. You can re-enable it and include its 547 results with other flags and behaviors you define by using this directive. 548 549 ### ListView 550 551 > Value: `bool` (default: `false`) 552 553 This alters the appearance of the autocompletion suggestions "popup". Rather 554 than suggestions being in a grid layout (with descriptions overwriting the 555 hint text) the suggestions are in a list view with the descriptions next to 556 them on the same row (similar to how an IDE might display it's suggestions). 557 558 ### NestedCommand 559 560 > Value: `bool` (default: `false`) 561 562 Only enable this if the command you are autocompleting is a nested parameter 563 of the parent command you have types. For example with `sudo`, once you've 564 typed the command name you wish to elivate, then you would want suggestions 565 for that command rather than for `sudo` itself. 566 567 ### Optional 568 569 > Value: `bool` (default: `false`) 570 571 Specifies if a match is required for the index in this schema. ie optional 572 flags.