Skip to content

Commit 26821e1

Browse files
authored
fix(completion): cross-platform shell auto-detection for Windows paths and .exe extensions (#273)
* fix(completion): cross-platform shell auto-detection for Windows paths and .exe extensions * chore: trigger PR triage gate re-run
1 parent 92ebb2f commit 26821e1

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/commands/completion.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@ describe('isShell / detectShell', () => {
2323
expect(detectShell({ SHELL: '/usr/local/bin/fish' })).toBe('fish');
2424
});
2525

26+
it('detects shells with Windows backslashes, .exe suffixes, and uppercase paths', () => {
27+
expect(detectShell({ SHELL: 'C:\\Program Files\\Git\\bin\\bash.exe' })).toBe('bash');
28+
expect(detectShell({ SHELL: 'C:\\tools\\zsh.exe' })).toBe('zsh');
29+
expect(detectShell({ SHELL: '/usr/bin/FISH.EXE' })).toBe('fish');
30+
expect(detectShell({ SHELL: 'C:/Program Files\\Git\\bin/bash.exe' })).toBe('bash');
31+
});
32+
2633
it('returns undefined for an unknown or missing shell', () => {
2734
expect(detectShell({ SHELL: '/bin/sh' })).toBeUndefined();
35+
expect(detectShell({ SHELL: 'C:\\Windows\\System32\\cmd.exe' })).toBeUndefined();
2836
expect(detectShell({})).toBeUndefined();
2937
});
3038
});

src/commands/completion.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export function isShell(value: string): value is Shell {
4242
/** Best-effort shell detection from `$SHELL` (e.g. "/bin/zsh" -> "zsh"). */
4343
export function detectShell(env: NodeJS.ProcessEnv): Shell | undefined {
4444
const shellPath = env.SHELL ?? '';
45-
const base = shellPath.slice(shellPath.lastIndexOf('/') + 1);
45+
const rawBase = shellPath.split(/[/\\]/).pop() ?? '';
46+
const base = rawBase.toLowerCase().replace(/\.exe$/, '');
4647
return isShell(base) ? base : undefined;
4748
}
4849

0 commit comments

Comments
 (0)