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

# Shell 集成 [功能预览]

> 将你的 shell 接入 Devin，以便即时调用，并让 Devin 了解你最近执行的命令。

<Info>
  Shell 集成目前属于**功能预览**。它可在 macOS、Linux 和 WSL 上配合 Bash、Zsh 和 Fish 使用。Shell 集成暂不支持 Windows (PowerShell 或 CMD) 。不过，你仍然可以在 Windows 上运行 Devin CLI——只是暂时无法使用此功能。该功能已基本完整，但与某些其他 shell 功能的兼容性可能不佳。如果你遇到不兼容的情况，请告诉我们！
</Info>

Shell 集成会接入你现有的 shell 会话，让 Devin 与其一同运行。完成设置后，你可以：

* 在 shell 中的任意位置按 **Ctrl+G** (可配置) ，以当前命令行作为上下文调用 Devin
* 输入 `# <message>` 并按 Enter，直接将其发送给 Devin (仅限 Zsh)
* 让 Devin 自动获取你最近执行的 shell 命令及其输出

为获得最佳支持，我们强烈建议使用 `zsh`，而不是 `bash` 或 `fish`。

***

<div id="setup">
  ## 设置
</div>

运行 setup 命令，在你的 shell 配置文件中安装 Shell 集成：

```bash theme={null}
devin shell setup
```

这会将受管理的块添加到你的 shell rc 文件 (`~/.bashrc`、`~/.zshrc` 或 `~/.config/fish/config.fish`) 中。然后重启终端，或使用 source 命令加载该配置：

<Tabs>
  <Tab title="Bash">
    ```bash theme={null}
    source ~/.bashrc
    ```
  </Tab>

  <Tab title="Zsh">
    ```bash theme={null}
    source ~/.zshrc
    ```
  </Tab>

  <Tab title="Fish">
    ```fish theme={null}
    source ~/.config/fish/config.fish
    ```
  </Tab>
</Tabs>

你也可以显式指定某个 shell：

```bash theme={null}
devin shell setup bash
devin shell setup zsh
devin shell setup fish
```

<Note>
  Shell 集成与 `devin setup` 向导彼此独立。运行 `devin setup` **不会**安装 Shell 集成——你必须另行运行 `devin shell setup`。
</Note>

***

<div id="features">
  ## 功能
</div>

<video controls className="w-full aspect-video" src="https://mintcdn.com/cognitionai/aB0LGhNhil-hGeEB/images/cli/devin4terminal.mp4?fit=max&auto=format&n=aB0LGhNhil-hGeEB&q=85&s=c87bfe2ff72b14fea8e939752f5da857" data-path="images/cli/devin4terminal.mp4" />

<div id="ctrlg-shortcut-configurable">
  ### Ctrl+G 快捷键 (可配置)
</div>

在 shell 中任意位置按下 **Ctrl+G** 即可调用 Devin。你在当前行输入的任何内容都会连同你最近的 shell 历史记录一起，作为上下文传递给 Devin。

```bash theme={null}
$ git status   # 输入此命令，然后按 Ctrl+G 而非 Enter
# Devin 将以 "git status" 作为上下文，并附带你最近的 shell 历史记录
```

这在 Bash、Zsh 和 Fish 中都可用。

<div id="comment-syntax-zsh-only">
  ### 注释语法 (仅限 Zsh)
</div>

在 Zsh 中，先在行首输入 `#`，再键入一条自然语言消息，然后按 Enter。Devin 会将这条注释作为提示接收。

```bash theme={null}
$ # explain what this directory contains
# Devin 将以你的注释作为提示启动
```

<Note>
  使用注释语法需要启用 Zsh 的 `INTERACTIVE_COMMENTS` 选项，而 Shell 集成会自动启用该选项。
</Note>

<div id="shell-history-context">
  ### Shell 历史上下文
</div>

通过 Ctrl+G 或注释语法调用时，Devin 可以看到你最近的 shell 命令*及其输出*。这样，Devin 就能了解你刚才在做什么，无需你额外解释，也能提供更有针对性的帮助。

***

<div id="removing-shell-integration">
  ## 移除 Shell 集成
</div>

要移除 Shell 集成，请从你的 shell 配置文件 (`~/.bashrc`、`~/.zshrc` 或 `~/.config/fish/config.fish`) 中删除受管理的块。找到 `BEGIN MANAGED` 和 `END MANAGED` 标记之间的内容，并删除整个块。然后重启终端。

***

<div id="configuration">
  ## 配置
</div>

在你的[配置文件](/zh/cli/reference/configuration/config-file)中配置 Shell 集成的行为：

```json theme={null}
// ~/.config/devin/config.json
{
  "shell": {
    "keybinding_trigger": "C-g",
    "enable_comments": true
  }
}
```

| 选项                         | 默认值     | 说明                                                                                |
| -------------------------- | ------- | --------------------------------------------------------------------------------- |
| `shell.keybinding_trigger` | `"C-g"` | 用于在 shell 中触发 Devin 的按键绑定。Ctrl 请使用 `C-` 前缀 (例如，`"C-g"` 表示 Ctrl+G) 。设为 `null` 可禁用。 |
| `shell.enable_comments`    | `true`  | 在 Zsh 中启用 `# comment` 语法，以便向 Devin 发送消息。                                          |

<Note>
  更改配置后，请再次运行 `devin shell setup`，并重启终端，使更改生效。
</Note>
