diff --git a/.changeset/curvy-clouds-hide.md b/.changeset/curvy-clouds-hide.md new file mode 100644 index 0000000..ce812a9 --- /dev/null +++ b/.changeset/curvy-clouds-hide.md @@ -0,0 +1,5 @@ +--- +'@bomb.sh/tab': patch +--- + +Fix PowerShell completion argument parsing diff --git a/bin/cli.ts b/bin/cli.ts index b860f22..cf5dfc1 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -9,6 +9,11 @@ const shells = ['zsh', 'bash', 'fish', 'powershell']; async function main() { const args = process.argv.slice(2); + const isPowerShell = process.platform === 'win32' && process.env.PSModulePath; + + if (process.env.TAB_DEBUG) { + console.error('RAW ARGS:', process.argv); + } // complete -- if (args.length >= 2 && args[1] === 'complete') { @@ -23,16 +28,27 @@ async function main() { } const dashIndex = process.argv.indexOf('--'); - if (dashIndex !== -1) { - const completion = new PackageManagerCompletion(packageManager); - await setupCompletionForPackageManager(packageManager, completion); - const toComplete = process.argv.slice(dashIndex + 1); - await completion.parse(toComplete); - process.exit(0); - } else { + // PowerShell's argument parsing can normalize or drop a `--` + // our " complete -- " POSIX-style contract doesn't work the same way. + // so we need to handle the PowerShell case separately. + // gh issue discussion: https://github.com/bombshell-dev/tab/issues/82 + + const completionArgs = + dashIndex !== -1 && (!isPowerShell || dashIndex < process.argv.length - 1) + ? process.argv.slice(dashIndex + 1) + : isPowerShell + ? args.slice(2) + : null; + + if (!completionArgs) { console.error(`Error: Expected '--' followed by command to complete`); process.exit(1); } + + const completion = new PackageManagerCompletion(packageManager); + await setupCompletionForPackageManager(packageManager, completion); + await completion.parse(completionArgs); + process.exit(0); } //