mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 22:03:45 +00:00
better bash detection on unix - also try PATH
This commit is contained in:
parent
b065ce75b5
commit
f97ce5ada1
1 changed files with 28 additions and 6 deletions
|
|
@ -7,14 +7,31 @@ import { SettingsManager } from "../core/settings-manager.js";
|
|||
let cachedShellConfig: { shell: string; args: string[] } | null = null;
|
||||
|
||||
/**
|
||||
* Find bash executable on PATH (Windows)
|
||||
* Find bash executable on PATH (cross-platform)
|
||||
*/
|
||||
function findBashOnPath(): string | null {
|
||||
if (process.platform === "win32") {
|
||||
// Windows: Use 'where' and verify file exists (where can return non-existent paths)
|
||||
try {
|
||||
const result = spawnSync("where", ["bash.exe"], { encoding: "utf-8", timeout: 5000 });
|
||||
if (result.status === 0 && result.stdout) {
|
||||
const firstMatch = result.stdout.trim().split(/\r?\n/)[0];
|
||||
if (firstMatch && existsSync(firstMatch)) {
|
||||
return firstMatch;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Unix: Use 'which' and trust its output (handles Termux and special filesystems)
|
||||
try {
|
||||
const result = spawnSync("where", ["bash.exe"], { encoding: "utf-8", timeout: 5000 });
|
||||
const result = spawnSync("which", ["bash"], { encoding: "utf-8", timeout: 5000 });
|
||||
if (result.status === 0 && result.stdout) {
|
||||
const firstMatch = result.stdout.trim().split(/\r?\n/)[0];
|
||||
if (firstMatch && existsSync(firstMatch)) {
|
||||
if (firstMatch) {
|
||||
return firstMatch;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,8 +46,7 @@ function findBashOnPath(): string | null {
|
|||
* Resolution order:
|
||||
* 1. User-specified shellPath in settings.json
|
||||
* 2. On Windows: Git Bash in known locations, then bash on PATH
|
||||
* 3. On Unix: /bin/bash
|
||||
* 4. Fallback: sh
|
||||
* 3. On Unix: /bin/bash, then bash on PATH, then fallback to sh
|
||||
*/
|
||||
export function getShellConfig(): { shell: string; args: string[] } {
|
||||
if (cachedShellConfig) {
|
||||
|
|
@ -86,12 +102,18 @@ export function getShellConfig(): { shell: string; args: string[] } {
|
|||
);
|
||||
}
|
||||
|
||||
// Unix: prefer bash over sh
|
||||
// Unix: try /bin/bash, then bash on PATH, then fallback to sh
|
||||
if (existsSync("/bin/bash")) {
|
||||
cachedShellConfig = { shell: "/bin/bash", args: ["-c"] };
|
||||
return cachedShellConfig;
|
||||
}
|
||||
|
||||
const bashOnPath = findBashOnPath();
|
||||
if (bashOnPath) {
|
||||
cachedShellConfig = { shell: bashOnPath, args: ["-c"] };
|
||||
return cachedShellConfig;
|
||||
}
|
||||
|
||||
cachedShellConfig = { shell: "sh", args: ["-c"] };
|
||||
return cachedShellConfig;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue