dsh-git-bash
为 DSH 提供一个名为 bash 的工具,直接调用本机 Git Bash(bash.exe)执行命令。
Git Bash 的安装路径可配置,留空则自动探测常见位置。
- 零运行时依赖:只 import node 内建模块,安装为 profile 的 bundle 时无需构建。
- 命令通过
bash --login -c ""执行(loginShell可关闭),工作目录由 spawn 的 cwd 决定。 - 退出码原样透传;非零退出只上报、不抛错(结果里带
exitCode与[exit code: N])。 - stdout+stderr 按原始顺序合并,超过
maxOutputBytes时截断并标记。 - 支持取消与超时:tool 被取消或到达
timeoutMs时会结束整棵进程树(Windows 用taskkill /T)。
安装
在 DSH 里把本目录作为 bundle 安装:
plugin_manager action=install_bundle target=D:\dsh\plugins\dsh-git-bash
安装后重启/重载 profile(或按设置页提示重开)。
工具:bash
| 参数 | 类型 | 说明 |
|---|---|---|
command |
string(必填) | 传给 bash -c 的命令行。 |
workdir |
string | 工作目录(Windows 路径如 D:\x,或 bash 路径如 /d/x)。默认取 defaultWorkdir,否则取会话工作目录。 |
timeoutMs |
integer | 超时毫秒数,到点终止。默认取 defaultTimeoutMs。 |
返回对象:{ output: string, exitCode: integer, truncated: boolean }。
配置(插件页可视化表单 / cordis.patch.yml 的 config)
最方便的方式:在插件页可视化改。 打开「插件」页 → 查看 dsh-git-bash → 组件行右侧的「配置」按钮(或 bundle 详情页里的「配置」区块)→ 填写 Git Bash 路径、默认工作目录、超时、输出上限、登录 Shell → 点「保存」立即生效(写入当前 profile 的 user 配置层,无需重启)。
该表单由本插件自带的浏览器端(lib/client.js,通过 package.json 的 dsh.client 声明)注册到插件页的两个插槽:plugins.row.config(key dsh-git-bash#dsh-git-bash,让组件行出现可点入的「配置」页)与 plugins.bundle.config(key dsh-git-bash,在 bundle 详情页内联渲染)。
两个必要条件(都不满足时会出现「该插件当前未加载,暂时无法配置」或根本不显示配置区):
1. index.js 的 Config schema 里每个字段都必须是 .volatile(),否则 dsh-settings 的 volatileForm 会返回 undefined 而跳过该命名空间。
2. index.js 必须能在 Host 进程的环境里解析到 @deepseek-ai/schemastery。Host 不一定继承 DSH_PROFILE_DIR/DSH_HOME,所以 schemaBases() 会直接扫描 ~/.dsh/profiles/*(并兜底全局 npm 目录)。若 Config 解析失败(cordis_inspect_query 的 Config listConfigs 对该条目返回 status:"absent"),插件页就永远没有配置表单。
> 首次部署或改动 index.js / package.json 的 dsh 清单后,需要重启一次 DSH Web(Host):Node 会缓存已加载的 ES 模块,仅重启插件条目不足以重新求值 Config。之后改 lib/client.js 只需刷新页面。
配置项的底层来源仍是本 bundle 的 cordis.patch.yml 里的 config(schema 见 index.js 的 Config);可视化表单改的是 profile 的 user 覆盖层,优先级更高。
| 字段 | 默认 | 说明 |
|---|---|---|
gitBashPath |
D:\soft\Git\bin\bash.exe(本机 patch 里显式指定) |
bash.exe 路径;也可填 Git 安装目录(自动补 bin/bash.exe、usr/bin/bash.exe)。留空自动探测。 |
defaultWorkdir |
空 | 未传 workdir 时的工作目录;空 = 会话工作目录。 |
defaultTimeoutMs |
120000 |
默认超时(毫秒)。 |
loginShell |
true |
是否以登录 shell(--login)执行,登录 shell 会加载 /etc/profile,PATH 更完整。 |
maxOutputBytes |
1048576 |
输出合并后上限字节数,超出截断。 |
说明
- 自动探测顺序:
D:\soft\Git\{bin,usr\bin}\bash.exe→C:\Program Files\Git\bin\bash.exe→
C:\Program Files (x86)\Git\bin\bash.exe→%ProgramFiles%、%ProgramFiles(x86)%、
%LOCALAPPDATA%下的 Git 安装 → PATH 上的bash。 - 若
gitBashPath指向的文件不存在,工具会在结果里给出「启动 Git Bash 失败(路径):…」的明确错误。