diff --git a/src/commands/completion.test.ts b/src/commands/completion.test.ts index 8388a09..c1bbdcf 100644 --- a/src/commands/completion.test.ts +++ b/src/commands/completion.test.ts @@ -23,8 +23,16 @@ describe('isShell / detectShell', () => { expect(detectShell({ SHELL: '/usr/local/bin/fish' })).toBe('fish'); }); + it('detects shells with Windows backslashes, .exe suffixes, and uppercase paths', () => { + expect(detectShell({ SHELL: 'C:\\Program Files\\Git\\bin\\bash.exe' })).toBe('bash'); + expect(detectShell({ SHELL: 'C:\\tools\\zsh.exe' })).toBe('zsh'); + expect(detectShell({ SHELL: '/usr/bin/FISH.EXE' })).toBe('fish'); + expect(detectShell({ SHELL: 'C:/Program Files\\Git\\bin/bash.exe' })).toBe('bash'); + }); + it('returns undefined for an unknown or missing shell', () => { expect(detectShell({ SHELL: '/bin/sh' })).toBeUndefined(); + expect(detectShell({ SHELL: 'C:\\Windows\\System32\\cmd.exe' })).toBeUndefined(); expect(detectShell({})).toBeUndefined(); }); }); diff --git a/src/commands/completion.ts b/src/commands/completion.ts index 15cf7a4..42668fa 100644 --- a/src/commands/completion.ts +++ b/src/commands/completion.ts @@ -42,7 +42,8 @@ export function isShell(value: string): value is Shell { /** Best-effort shell detection from `$SHELL` (e.g. "/bin/zsh" -> "zsh"). */ export function detectShell(env: NodeJS.ProcessEnv): Shell | undefined { const shellPath = env.SHELL ?? ''; - const base = shellPath.slice(shellPath.lastIndexOf('/') + 1); + const rawBase = shellPath.split(/[/\\]/).pop() ?? ''; + const base = rawBase.toLowerCase().replace(/\.exe$/, ''); return isShell(base) ? base : undefined; }