Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/advanced/bash-completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,39 @@ By running `bashly generate --upgrade`, your completions function
(generated with `bashly add completions`) will be regenerated.
!!!

## Custom command completions
## Custom argument completions

In addition to the automatic suggestion of subcommands and flags, you can
instruct bashly to also suggest files, directories, users, git branches and
more. To do this, add another option in your `bashly.yml` on the command you
wish to alter:
more.

For positional arguments, add `completions` to the argument that should receive
these suggestions:

```yaml bashly.yml
commands:
- name: upload
help: Upload a file
completions:
- <directory>
- <user>
- $(git branch 2> /dev/null)
args:
- name: source
help: File to upload
required: true
completions:
- <file>
- <directory>
- $(git branch 2> /dev/null)

```

The `completions` option is still supported on commands as a fallback for
positional arguments, but it is discouraged for new configurations. Prefer
placing completions directly on the relevant `args` entry.

## Custom flag completions

The `completions` option is also available on flags that have an `arg`.
Similarly to the `allowed` option for arguments, the allowed list is added
to the suggestions automatically (without the need to use `completions`).
For flag values, add `completions` to flags that have an `arg`. Similarly to
the `allowed` option for arguments and flags, the allowed list is added to the
suggestions automatically (without the need to use `completions`).

```yaml bashly.yml
commands:
Expand All @@ -78,7 +88,7 @@ commands:
```

- Anything between `<...>` will be added using the `compgen -A action` flag.
- Anything else, will be appended to the `compgen -W` flag.
- Anything else will be appended to the `compgen -W` flag.

!!! Note
In case you are using the
Expand Down
12 changes: 12 additions & 0 deletions src/configuration/argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,21 @@ define required arguments after it.
Limit the allowed values to a specified whitelist. Can be used in conjunction
with [`default`](#default) or [`required`](#required).

Allowed values are also added to generated bash completions automatically.

[!button variant="primary" icon="code-review" text="Whitelist Example"](https://github.com/bashly-framework/bashly/tree/master/examples/whitelist#readme)


### completions

[!badge Array of Strings]

Specify an array of additional completion suggestions when used in conjunction
with `bashly add completions`.

[!ref](/advanced/bash-completion.md)


### repeatable

[!badge Boolean]
Expand Down
5 changes: 5 additions & 0 deletions src/configuration/command.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ To access arguments captured by `catch_all` in your script, use the
Specify an array of additional completion suggestions when used in conjunction
with `bashly add completions`.

This command-level option is supported as a fallback for positional arguments,
but it is discouraged for new configurations. Prefer setting
[`completions`](argument.md#completions) on the relevant argument, or on the
relevant [`flag`](flag.md#completions) when completing a flag value.

[!ref](/advanced/bash-completion.md)


Expand Down
4 changes: 2 additions & 2 deletions src/configuration/flag.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ This option should be specified on both sides of the exclusivity.

[!badge Array of Strings]

Specify an array of additional completion suggestions when used in conjunction
with `bashly add completions`.
Specify an array of additional completion suggestions for this flag's value
when used in conjunction with `bashly add completions`.

Remember to set the [`arg`](#arg) name when using this option.

Expand Down