MCPcopy Index your code
hub / github.com/codeaashu/claude-code / findPowerShell

Function findPowerShell

src/utils/shell/powershellDetection.ts:24–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 * Windows/macOS, PATH is sufficient.
23 */
24export async function findPowerShell(): Promise<string | null> {
25 const pwshPath = await which('pwsh')
26 if (pwshPath) {
27 // Snap launcher hangs in subprocesses. Prefer the direct binary.
28 // Check both the resolved PATH entry and its symlink target: on
29 // some distros /usr/bin/pwsh is a symlink to /snap/bin/pwsh, which
30 // would bypass a naive startsWith('/snap/') on the which() result.
31 if (getPlatform() === 'linux') {
32 const resolved = await realpath(pwshPath).catch(() => pwshPath)
33 if (pwshPath.startsWith('/snap/') || resolved.startsWith('/snap/')) {
34 const direct =
35 (await probePath('/opt/microsoft/powershell/7/pwsh')) ??
36 (await probePath('/usr/bin/pwsh'))
37 if (direct) {
38 const directResolved = await realpath(direct).catch(() => direct)
39 if (
40 !direct.startsWith('/snap/') &&
41 !directResolved.startsWith('/snap/')
42 ) {
43 return direct
44 }
45 }
46 }
47 }
48 return pwshPath
49 }
50
51 const powershellPath = await which('powershell')
52 if (powershellPath) {
53 return powershellPath
54 }
55
56 return null
57}
58
59let cachedPowerShellPath: Promise<string | null> | null = null
60

Callers 1

getCachedPowerShellPathFunction · 0.85

Calls 2

getPlatformFunction · 0.85
probePathFunction · 0.85

Tested by

no test coverage detected