# apigenie completion

Source: https://api-genie.dev/docs/reference/cli/completion
Part of the reference of [apigenie](https://api-genie.dev/docs/reference/cli.md).
Its other pages: [bundle](https://api-genie.dev/docs/reference/cli/bundle.md), [changelog](https://api-genie.dev/docs/reference/cli/changelog.md), [commands](https://api-genie.dev/docs/reference/cli/command-index.md), [config](https://api-genie.dev/docs/reference/cli/config.md), [convert](https://api-genie.dev/docs/reference/cli/convert.md), [credits](https://api-genie.dev/docs/reference/cli/credits.md), [diff](https://api-genie.dev/docs/reference/cli/diff.md), [evolve](https://api-genie.dev/docs/reference/cli/evolve.md), [format](https://api-genie.dev/docs/reference/cli/format.md), [i18n](https://api-genie.dev/docs/reference/cli/i18n.md), [init](https://api-genie.dev/docs/reference/cli/init.md), [license](https://api-genie.dev/docs/reference/cli/license.md), [lint](https://api-genie.dev/docs/reference/cli/lint.md), [overlay](https://api-genie.dev/docs/reference/cli/overlay.md), [run](https://api-genie.dev/docs/reference/cli/run.md), [test](https://api-genie.dev/docs/reference/cli/test.md), [window](https://api-genie.dev/docs/reference/cli/window.md).

Since 0.13.0, `apigenie completion` prints the script that completes the commands, options and option values of
`apigenie` in bash, zsh, fish or PowerShell. The script is written from the commands that
[`apigenie commands`](/docs/reference/cli/command-index) lists, so it completes what the version
that printed it accepts. `apigenie-generator completion` and `apigenie-catalog completion` print the
scripts of those binaries.

## Usage

```sh
apigenie completion SHELL
```

`SHELL` is `bash`, `zsh`, `fish` or `powershell`. The script goes to the standard output; load it
from the shell's startup file:

| Shell | Startup file | Line |
| --- | --- | --- |
| bash | `~/.bashrc` | `eval "$(apigenie completion bash)"` |
| zsh | `~/.zshrc`, after `compinit` | `source <(apigenie completion zsh)` |
| fish | `~/.config/fish/config.fish` | `apigenie completion fish \| source` |
| PowerShell | `$PROFILE` | `apigenie completion powershell \| Out-String \| Invoke-Expression` |

The `eval` line works in every bash, the 3.2 of macOS included. For `apigenie-generator` and
`apigenie-catalog`, use the same lines with their names.

A saved script loads without starting `apigenie` at every shell start; save it again after an
upgrade. zsh loads `_apigenie` from a directory of `$fpath`; add `fpath=(~/.zsh/completions $fpath)`
to `~/.zshrc` before `compinit`. fish loads `~/.config/fish/completions/apigenie.fish`:

```sh
mkdir -p ~/.zsh/completions ~/.config/fish/completions
apigenie completion zsh > ~/.zsh/completions/_apigenie
apigenie completion fish > ~/.config/fish/completions/apigenie.fish
```

## What it completes

- The commands and subcommands: `apigenie i<Tab>` offers `i18n` and `init`.
- The options of the command typed so far, after a `-`: `apigenie lint --f<Tab>` offers `--fix`
  and `--formatter`. zsh, fish and PowerShell show what each option does.
- The values of an option that accepts only some, such as the formats of
  `apigenie diff --formatter`, and of a positional argument that does, such as the shell of
  `apigenie completion`.
- File names for the other values and for positional arguments, as the shell completes them.

## Options

`completion` has no options besides `-h`/`--help` and
[`--json`](/docs/reference/cli#json-output). With `--json`, the script is the `output` of the status
document.

## Exit status

0 when the script is printed. 2 when `SHELL` is missing or is not one of the four, or on an unknown
option.

## See also

- [commands](/docs/reference/cli/command-index): Every command with its arguments and options, as a list or as JSON.
