Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/bombshell-dev/tab. shell autocompletions for javascript CLIs
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192#!/usr/bin/env node
import { script } from '../src/t.js';import { PackageManagerCompletion } from './package-manager-completion.js';
const packageManagers = ['npm', 'pnpm', 'yarn', 'bun'];const shells = ['zsh', 'bash', 'fish', 'powershell'];
async function main() { const args = process.argv.slice(2); const isPowerShell = process.platform === 'win32' && process.env.PSModulePath;
// <packageManager> complete -- <args> if (args.length >= 2 && args[1] === 'complete') { const packageManager = args[0];
if (!packageManagers.includes(packageManager)) { console.error(`Error: Unsupported package manager "${packageManager}"`); console.error( `Supported package managers: ${packageManagers.join(', ')}` ); process.exit(1); }
const dashIndex = process.argv.indexOf('--'); // PowerShell's argument parsing can normalize or drop a `--` // our "<pm> complete -- <query>" 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); }
// Note: we intentionally do NOT build the package manager's command tree // here. `parse` builds it lazily and only when it actually needs to // complete the package manager itself, so the delegation path never pays // for a `<pm> --help` parse. const completion = new PackageManagerCompletion(packageManager); await completion.parse(completionArgs); process.exit(0); }
// <packageManager> <shell> if (args.length === 2) { const [packageManager, shell] = args;
if (!packageManagers.includes(packageManager)) { console.error(`Error: Unsupported package manager "${packageManager}"`); console.error( `Supported package managers: ${packageManagers.join(', ')}` ); process.exit(1); }
if (!shells.includes(shell)) { console.error(`Error: Unsupported shell "${shell}"`); console.error(`Supported shells: ${shells.join(', ')}`); process.exit(1); }
generateCompletionScript(packageManager, shell); process.exit(0); }
console.error('Usage: tab <packageManager> <shell>'); console.error(` tab <packageManager> complete -- <args>`); process.exit(1);}
function generateCompletionScript(packageManager: string, shell: string) { const name = packageManager;
const isLocalDev = process.argv[1].endsWith('dist/bin/cli.js');
const executable = isLocalDev ? `node ${process.argv[1]} ${packageManager}` : `tab ${packageManager}`;
script(shell as any, name, executable);}
main().catch(console.error);