mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-05 00:18:05 +00:00
fix(codex-auth): stop spawning powershell in shell detection (#1348)
This commit is contained in:
@@ -3,8 +3,6 @@
|
|||||||
* Determines current shell to emit correct eval-safe export syntax.
|
* Determines current shell to emit correct eval-safe export syntax.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as childProcess from 'child_process';
|
|
||||||
|
|
||||||
export type Shell = 'bash' | 'zsh' | 'fish' | 'pwsh' | 'cmd';
|
export type Shell = 'bash' | 'zsh' | 'fish' | 'pwsh' | 'cmd';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +18,7 @@ export function detectShell(
|
|||||||
if (platform === 'win32') {
|
if (platform === 'win32') {
|
||||||
return (
|
return (
|
||||||
shellFromExecutable(env.SHELL) ??
|
shellFromExecutable(env.SHELL) ??
|
||||||
shellFromExecutable(parentProcessName ?? detectParentProcessName(platform)) ??
|
shellFromExecutable(parentProcessName) ??
|
||||||
shellFromExecutable(env.ComSpec ?? env.COMSPEC) ??
|
shellFromExecutable(env.ComSpec ?? env.COMSPEC) ??
|
||||||
'cmd'
|
'cmd'
|
||||||
);
|
);
|
||||||
@@ -31,26 +29,6 @@ export function detectShell(
|
|||||||
return 'bash'; // default for bash, sh, dash, ksh
|
return 'bash'; // default for bash, sh, dash, ksh
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectParentProcessName(platform: string): string | undefined {
|
|
||||||
if (platform !== 'win32' || !Number.isInteger(process.ppid) || process.ppid <= 0) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = childProcess.spawnSync(
|
|
||||||
'powershell.exe',
|
|
||||||
[
|
|
||||||
'-NoProfile',
|
|
||||||
'-NonInteractive',
|
|
||||||
'-Command',
|
|
||||||
`(Get-Process -Id ${process.ppid} -ErrorAction Stop).ProcessName`,
|
|
||||||
],
|
|
||||||
{ encoding: 'utf8', timeout: 1500, windowsHide: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result.status !== 0 || !result.stdout) return undefined;
|
|
||||||
return result.stdout.trim().split(/\r?\n/).pop()?.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
function shellFromExecutable(value: string | undefined): Shell | null {
|
function shellFromExecutable(value: string | undefined): Shell | null {
|
||||||
if (!value) return null;
|
if (!value) return null;
|
||||||
const base = value
|
const base = value
|
||||||
|
|||||||
Reference in New Issue
Block a user