jackwener/OpenCLI · error · CliError

UNSUPPORTED_SHELL

UNSUPPORTED_SHELL

Error message

Unsupported shell: ${shell}. Supported: bash, zsh, fish

What it means

printCompletionScript generates shell completion scripts for bash, zsh, and fish only. A request for any other shell (or an unrecognized value) throws a CliError with code UNSUPPORTED_SHELL. The error is thrown from the default branch of the shell switch before any script is emitted.

Source

Thrown at src/completion.ts:80

// ── Shell script generators ────────────────────────────────────────────────

/**
 * Print the completion script for the requested shell.
 */
export function printCompletionScript(shell: string): void {
  switch (shell) {
    case 'bash':
      process.stdout.write(bashCompletionScript());
      break;
    case 'zsh':
      process.stdout.write(zshCompletionScript());
      break;
    case 'fish':
      process.stdout.write(fishCompletionScript());
      break;
    default:
      throw new CliError('UNSUPPORTED_SHELL', `Unsupported shell: ${shell}. Supported: bash, zsh, fish`);
  }
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Request one of the supported shells explicitly: bash, zsh, or fish (lowercase).
  2. For unsupported shells, use the closest supported script or a community completion solution.
  3. In scripts, detect the shell from $SHELL basename and map unsupported shells to an error/alternative before calling the completion command.

Example fix

// before
opencli completion powershell
// after
opencli completion zsh  # or bash / fish
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['bash', 'zsh', 'fish'] as const;
const shell = process.env.SHELL?.split('/').pop() ?? '';
if (!SUPPORTED.includes(shell as any)) {
  throw new Error(`Shell '${shell}' unsupported; use bash, zsh, or fish`);
}

Type guard

type SupportedShell = 'bash' | 'zsh' | 'fish';
const isSupportedShell = (s: unknown): s is SupportedShell =>
  s === 'bash' || s === 'zsh' || s === 'fish';

Try / catch

try {
  opencli.completion(shell);
} catch (e) {
  if (e.code === 'UNSUPPORTED_SHELL') {
    console.error(`${e.message}; generate for bash/zsh/fish instead.`);
  } else throw e;
}

Prevention

When it happens

Trigger: opencli completion powershell; opencli completion sh; opencli completion BASH (case-sensitive match); passing an unset/empty shell variable so the default branch is hit.

Common situations: Users of PowerShell, cmd, nushell, or tcsh asking for completions; scripts reading $SHELL which may report /bin/sh or an unsupported shell; setting the shell argument with different capitalization.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/237583bad0248fa9. Report an issue: GitHub.