You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Optional or required **option flags** (with or without flag arguments).
76
77
-**Commands** (and subcommands).
77
78
- Standard flags (like **--help** and **--version**).
79
+
- Preventing your script from running unless the command line is valid.
78
80
- Providing you with a place to input your code for each of the functions
79
81
your tool performs, and merging it back to the final script.
80
82
- Providing you with additional (optional) framework-style, standard
81
83
library functions:
82
84
-**Color output**.
83
85
-**Config file management** (INI format).
84
86
-**YAML parsing**.
87
+
-**Bash completions**.
85
88
- and more.
86
89
87
90
@@ -198,6 +201,7 @@ command and subcommands (under the `commands` definition).
198
201
`commands` | Specify the array of [commands](#command-options). Each command will have its own args and flags. Note: if `commands` is provided, you cannot specify flags or args at the same level.
199
202
`args` | Specify the array of [positional arguments](#argument-options) this script needs.
200
203
`flags` | Specify the array of option [flags](#flag-options) this script needs.
204
+
`completions` | Specify an array of additional completion suggestions when used in conjunction with `bashly add comp`. See [Bash Completions](#bash-completions).
201
205
`catch_all` | Specify that this command should allow for additional arbitrary arguments or flags. It can be set in one of three ways:<br>- Set to `true` to just enable it.<br>- Set to a string, to use this string in the usage help text.<br>- Set to a hash containing `label` and `help` keys, to show a detailed help for it when running with `--help`.
202
206
`dependencies` | Specify an array of any required external dependencies (commands). The script execution will be halted with a friendly error unless all dependency commands exist.
203
207
`group` | In case you have many commands, use this option to specify a caption to display before this command. This option is purely for display purposes, and needs to be specified only for the first command in each group.
@@ -326,6 +330,71 @@ The generated script will execute `git status`.
326
330
See the [extensible-delegate example](examples/extensible-delegate).
327
331
328
332
333
+
## Bash Completions
334
+
335
+
Bashly comes with built-in bash completions generator, provided by the
336
+
[completely][completely] gem.
337
+
338
+
By running any of the `bashly add comp` commands, you can add this
339
+
functionality to your script in one of three ways:
340
+
341
+
-`bashly add comp function` - creates a function in your `./src/lib` directory
342
+
that echoes a completion script. You can then call this function from any
343
+
command (for example `yourcli completions`) and your users will be able to
344
+
install the completions by running `eval "$(yourcli completions)"`.
345
+
-`bashly add comp script` - creates a standalone completion script that can be
346
+
sourced or copies to the system's bash completions directory.
347
+
-`bashly add comp yaml` - creates the "raw data" YAML file. This is intended
348
+
mainly for development purposes.
349
+
350
+
The bash completions generation is completely automatic, and you will have to
351
+
rerun the `bashly add comp *` command whenever you change your `bashly.yml`
352
+
script.
353
+
354
+
In addition to suggesting subcommands and flags, you can instruct bashly to
355
+
also suggest files, directories, users and more. To do this, add another option
356
+
in your `bashly.yml` on the command you wish to alter:
357
+
358
+
```yaml
359
+
# bashly.yml
360
+
commands:
361
+
- name: upload
362
+
help: Upload a file
363
+
completions: [directory, user]
364
+
365
+
```
366
+
367
+
Valid completion additions are:
368
+
369
+
| Keyword | Meaning
370
+
|-------------|---------------------
371
+
| `alias` | Alias names
372
+
| `arrayvar` | Array variable names
373
+
| `binding` | Readline key binding names
374
+
| `builtin` | Names of shell builtin commands
375
+
| `command` | Command names
376
+
| `directory` | Directory names
377
+
| `disabled` | Names of disabled shell builtins
378
+
| `enabled` | Names of enabled shell builtins
379
+
| `export` | Names of exported shell variables
380
+
| `file` | File names
381
+
| `function` | Names of shell functions
382
+
| `group` | Group names
383
+
| `helptopic` | Help topics as accepted by the help builtin
384
+
| `hostname` | Hostnames, as taken from the file specified by the HOSTFILE shell variable
385
+
| `job` | Job names
386
+
| `keyword` | Shell reserved words
387
+
| `running` | Names of running jobs
388
+
| `service` | Service names
389
+
| `signal` | Signal names
390
+
| `stopped` | Names of stopped jobs
391
+
| `user` | User names
392
+
| `variable` | Names of all shell variables
393
+
394
+
Note that these are taken from the [Programmable Completion Builtin][compgen],
395
+
and will simply be added using the `compgen -A action` command.
396
+
397
+
329
398
## Real World Examples
330
399
331
400
-[Rush][rush] - a Personal Package Manager
@@ -344,3 +413,5 @@ to contribute, feel free to [open an issue][issues].
Copy file name to clipboardExpand all lines: spec/approvals/examples/completions
+11-3Lines changed: 11 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,10 @@
1
+
+ bashly add comp function
2
+
created src/lib/send_completions.sh
3
+
4
+
In order to use it in your script, create a command or a flag (for example: cli completions or cli --completions) that calls the send_completions function.
5
+
Your users can then run something like this to enable completions:
0 commit comments