Files
superwork/vscode/src/cc/sessionLaunch.ts
T
chehongweo 3621729367 🐛 fix(vscode): 会话终端直接拉起 claude/codex,不再往 shell 里打命令,启动命令不再污染 zsh 历史
新建工单、实施、审查、测试、原型、续聊、冲突解决、会话管理和各种恢复会话,
都改成开终端时直接指定要跑的程序(用户默认 shell 以 -ilc 'exec "$@"' 拉起),
环境变量照常加载,参数原样传入。程序退出时标签页随之关闭。
提示词和配置文件路径里带单引号也不再拒绝执行,相关的转义和拦截全部删掉。
2026-09-29 04:40:35 +08:00

26 lines
961 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import * as path from 'node:path'
/**
* 会话终端直接由登录 shell 拉起目标程序,而不是开个空 shell 再往里打字:
* - `-il` 照常加载 .zprofile / .zshrc,PATH、mise 等环境与手动开终端一致
* - `-c` 执行的命令不进 shell 历史,超长的启动命令不污染历史补全
* - argv 走 `"$@"` 原样传进去,空格、引号、`$`、换行都不经 shell 解析
* - `exec` 让程序顶替 shell,程序退出时终端标签页随之关闭
*/
export interface SessionLaunch {
shellPath: string
shellArgs: string[]
}
const FALLBACK_SHELL = '/bin/zsh'
export function buildSessionLaunch(shell: string, argv: readonly string[]): SessionLaunch {
const shellPath = shell || FALLBACK_SHELL
// `-c` 后的第一个参数成为 $0,占位用 shell 自己的名字,后面的才是 "$@"。
return {
shellPath,
shellArgs: ['-ilc', 'exec "$@"', path.basename(shellPath), ...argv],
}
}