> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 补全

> 打印一个脚本,使你的 shell 在你按 Tab 时补全 XBOX CLI 命令、选项和值。

打印 shell 补全脚本,以便按 Tab 时从固定列表中补全 `xbox` 命令、选项和值。

```bash theme={null}
xbox completion <shell>
```

`<shell>` 为 `bash`、`zsh`、`fish` 或 `powershell`。该命令将脚本写入 stdout 并以 `0` 退出。它不发出网络请求,也不需要你登录。它不接受
`--output table`。

## 补全内容

* 各级命令和子命令,例如将 `play` 补全为 `playfab` 或 `playtest`。
* 命令接受的选项,包括全局选项。
* 来自固定列表的值,例如 `--output` 格式、`--supported-device` 值、`xbl config` 命令的
  `--scope` 值、`xbl config download` 的 `--view` 值,以及 `context set` 和 `context unset` 接受的键。

补全不会查找游戏测试、沙盒或生成等资源,也不会查找你保存的配置文件,因此仍需手动键入这些内容。

## 启用补全

将适用于你的 shell 的行添加到其启动文件中,然后打开新终端。若要先在当前终端中试用,请在其中运行同一行。

Bash,在 `~/.bashrc` 中:

```bash theme={null}
eval "$(xbox completion bash)"
```

Zsh,在 `~/.zshrc` 中,位于 `compinit` 运行之后:

```zsh theme={null}
source <(xbox completion zsh)
```

fish,在 `~/.config/fish/config.fish` 中:

```fish theme={null}
xbox completion fish | source
```

PowerShell,在 `$PROFILE` 指定的文件中:

```powershell theme={null}
xbox completion powershell | Out-String | Invoke-Expression
```

该脚本补全名为 `xbox` 的命令,因此 CLI 必须以该名称位于 `PATH` 中。

## 工作原理

每当你按 Tab 时,每个脚本都会使用到目前为止键入的命令行运行 `xbox`,向 CLI 请求候选项。CLI 根据其自身的命令树进行应答。它不会读取配置或已保存的上下文、不会让你登录、不会发送遥测数据,也不会写入任何内容。


## Related topics

- [安装](https://docs.xbox.com/zh-CN/tools/xbox-cli/installation.md)
- [命令](https://docs.xbox.com/zh-CN/tools/xbox-cli/commands.md)
- [XBOX CLI](https://docs.xbox.com/zh-CN/tools/xbox-cli/index.md)
