fix(desktop): resolve login shell when loading env (#26449)
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com>
This commit is contained in:
parent
ff16eb8dea
commit
80543fb5dc
2 changed files with 19 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
|
|
||||||
import { isNushell, mergeShellEnv, parseShellEnv } from "./shell-env"
|
import { isNushell, mergeShellEnv, parseShellEnv, resolveUserShell } from "./shell-env"
|
||||||
|
|
||||||
describe("shell env", () => {
|
describe("shell env", () => {
|
||||||
test("parseShellEnv supports null-delimited pairs", () => {
|
test("parseShellEnv supports null-delimited pairs", () => {
|
||||||
|
|
@ -34,6 +34,13 @@ describe("shell env", () => {
|
||||||
expect(env.OPENCODE_CLIENT).toBe("desktop")
|
expect(env.OPENCODE_CLIENT).toBe("desktop")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("resolveUserShell falls back to the login shell before /bin/sh", () => {
|
||||||
|
expect(resolveUserShell("/custom/env-shell", "/bin/zsh")).toBe("/custom/env-shell")
|
||||||
|
expect(resolveUserShell(undefined, "/bin/zsh")).toBe("/bin/zsh")
|
||||||
|
expect(resolveUserShell(undefined, "unknown")).toBe("/bin/sh")
|
||||||
|
expect(resolveUserShell(undefined, undefined)).toBe("/bin/sh")
|
||||||
|
})
|
||||||
|
|
||||||
test("isNushell handles path and binary name", () => {
|
test("isNushell handles path and binary name", () => {
|
||||||
expect(isNushell("nu")).toBe(true)
|
expect(isNushell("nu")).toBe(true)
|
||||||
expect(isNushell("/opt/homebrew/bin/nu")).toBe(true)
|
expect(isNushell("/opt/homebrew/bin/nu")).toBe(true)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { spawnSync } from "node:child_process"
|
import { spawnSync } from "node:child_process"
|
||||||
|
import { userInfo } from "node:os"
|
||||||
import { basename } from "node:path"
|
import { basename } from "node:path"
|
||||||
import { getLogger } from "./logging"
|
import { getLogger } from "./logging"
|
||||||
|
|
||||||
|
|
@ -6,8 +7,17 @@ const TIMEOUT = 5_000
|
||||||
|
|
||||||
type Probe = { type: "Loaded"; value: Record<string, string> } | { type: "Timeout" } | { type: "Unavailable" }
|
type Probe = { type: "Loaded"; value: Record<string, string> } | { type: "Timeout" } | { type: "Unavailable" }
|
||||||
|
|
||||||
|
export function resolveUserShell(envShell: string | undefined, loginShell: string | null | undefined) {
|
||||||
|
const resolvedLoginShell = loginShell && loginShell !== "unknown" ? loginShell : undefined
|
||||||
|
return envShell || resolvedLoginShell || "/bin/sh"
|
||||||
|
}
|
||||||
|
|
||||||
export function getUserShell() {
|
export function getUserShell() {
|
||||||
return process.env.SHELL || "/bin/sh"
|
try {
|
||||||
|
return resolveUserShell(process.env.SHELL, userInfo().shell)
|
||||||
|
} catch {
|
||||||
|
return resolveUserShell(process.env.SHELL, undefined)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseShellEnv(out: Buffer) {
|
export function parseShellEnv(out: Buffer) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue