Skip to content

Commit 060c025

Browse files
authored
fix: use pwsh stop parsing operator --% (#86)
* use pwsh stop parsing operator * fix: cli detect pwsh * remove operator * add debug log * exclude pwsh from having -- required * update * add -- manually * add -- manually * fix partial command detection * test empty string * i bet this will work * test * test * separator * add changeset * prettier * update * pwsh.ts * rm log
1 parent 7059386 commit 060c025

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

.changeset/curvy-clouds-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@bomb.sh/tab': patch
3+
---
4+
5+
Fix PowerShell completion argument parsing

bin/cli.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const shells = ['zsh', 'bash', 'fish', 'powershell'];
99

1010
async function main() {
1111
const args = process.argv.slice(2);
12+
const isPowerShell = process.platform === 'win32' && process.env.PSModulePath;
13+
14+
if (process.env.TAB_DEBUG) {
15+
console.error('RAW ARGS:', process.argv);
16+
}
1217

1318
// <packageManager> complete -- <args>
1419
if (args.length >= 2 && args[1] === 'complete') {
@@ -23,16 +28,27 @@ async function main() {
2328
}
2429

2530
const dashIndex = process.argv.indexOf('--');
26-
if (dashIndex !== -1) {
27-
const completion = new PackageManagerCompletion(packageManager);
28-
await setupCompletionForPackageManager(packageManager, completion);
29-
const toComplete = process.argv.slice(dashIndex + 1);
30-
await completion.parse(toComplete);
31-
process.exit(0);
32-
} else {
31+
// PowerShell's argument parsing can normalize or drop a `--`
32+
// our "<pm> complete -- <query>" POSIX-style contract doesn't work the same way.
33+
// so we need to handle the PowerShell case separately.
34+
// gh issue discussion: https://github.com/bombshell-dev/tab/issues/82
35+
36+
const completionArgs =
37+
dashIndex !== -1 && (!isPowerShell || dashIndex < process.argv.length - 1)
38+
? process.argv.slice(dashIndex + 1)
39+
: isPowerShell
40+
? args.slice(2)
41+
: null;
42+
43+
if (!completionArgs) {
3344
console.error(`Error: Expected '--' followed by command to complete`);
3445
process.exit(1);
3546
}
47+
48+
const completion = new PackageManagerCompletion(packageManager);
49+
await setupCompletionForPackageManager(packageManager, completion);
50+
await completion.parse(completionArgs);
51+
process.exit(0);
3652
}
3753

3854
// <packageManager> <shell>

0 commit comments

Comments
 (0)