针对shell路径判断方式进行优化

This commit is contained in:
2026-01-13 12:39:27 +00:00
parent 5892abf513
commit 55c3bdfdfc
2 changed files with 18 additions and 9 deletions

View File

@@ -13,12 +13,15 @@
"warn",
{
"selector": "import",
"format": [ "camelCase", "PascalCase" ]
"format": [
"camelCase",
"PascalCase"
]
}
],
"@typescript-eslint/semi": "warn",
"@typescript-eslint/semi": "off",
"curly": "warn",
"eqeqeq": "warn",
"eqeqeq": "off",
"no-throw-literal": "warn",
"semi": "off"
},

View File

@@ -42,19 +42,25 @@ export default class RemoteContainer {
const baseUrl = `vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}`;
const url = devstarDomain ? `${baseUrl}&devstar_domain=${devstarDomain}` : baseUrl;
// 通过终端的 creationOptions 获取 shell 路径
// 获取本地操作系统类型
// 在远程环境下os.platform() 返回的是远程系统,但这里我们需要的是本地系统
// 所以通过终端的 shell 路径来推断
const shellPath = (terminal.creationOptions as any)?.shellPath || '';
const isWindows = shellPath.toLowerCase().includes('powershell') ||
console.log('终端 shell 路径:', shellPath);
// 检测 WindowsWindows shell 路径包含反斜杠或特定关键字)
const isWindows = shellPath.includes('\\') ||
shellPath.toLowerCase().includes('powershell') ||
shellPath.toLowerCase().includes('pwsh') ||
shellPath.toLowerCase().includes('cmd');
if (isWindows) {
// PowerShell/CMD: 使用分号分隔URL 需要特殊的引号处理
console.log('检测到 Windows shell,使用 PowerShell 语法');
// Windows PowerShell/CMD: 使用分号分隔URL 需要特殊的引号处理
console.log('检测到 Windows 本地系统,使用 PowerShell/CMD 语法');
return `code --new-window; code --open-url '"${url}"'`;
} else {
// Bash/Zsh: 使用 && 分隔,标准双引号
console.log('检测到 Unix shell,使用 Bash 语法');
// macOS/Linux: 使用 && 分隔,标准双引号
console.log('检测到 Unix 本地系统macOS/Linux,使用 Bash/Zsh 语法');
return `code --new-window && code --open-url "${url}"`;
}
}