Skip to content

feat(completion): add shell completion scripts for bash, zsh, and fish#3194

Open
lrg913427-dot wants to merge 5 commits intoopenai:mainfrom
lrg913427-dot:feat/shell-completion
Open

feat(completion): add shell completion scripts for bash, zsh, and fish#3194
lrg913427-dot wants to merge 5 commits intoopenai:mainfrom
lrg913427-dot:feat/shell-completion

Conversation

@lrg913427-dot
Copy link
Copy Markdown

Summary

Add shell auto-completion support for the openai CLI tool.

Fixes #843

Changes

New files:

  • completions/openai.bash — Bash completion script
  • completions/openai.zsh — Zsh completion script
  • completions/openai.fish — Fish completion script
  • src/openai/cli/_completions.py — Completion generation module

Usage

# Bash
openai completion bash > ~/.openai-completion.bash
source ~/.openai-completion.bash

# Zsh
openai completion zsh > ~/.openai-completion.zsh
source ~/.openai-completion.zsh

# Fish
openai completion fish > ~/.config/fish/completions/openai.fish

Features

Completions include:

  • All subcommands (api, tools, chat, image, audio, etc.)
  • Model names with descriptions (e.g., gpt-4o:GPT-4o - Most capable model)
  • Voice options for TTS (alloy, echo, fable, onyx, nova, shimmer)
  • Image sizes (256x256, 512x512, 1024x1024, etc.)
  • Quality options (standard, hd)
  • All CLI flags and options

Testing

# Test bash completion
source completions/openai.bash
openai <TAB>           # Shows: api tools
openai api <TAB>       # Shows: chat image audio files models completions fine_tuning
openai api chat --model <TAB>  # Shows model names

Notes

  • Completion scripts are generated via openai completion <shell> command
  • Scripts are self-contained with no external dependencies
  • Works with bash 4+, zsh 5+, and fish 3+

Add shell auto-completion support for the openai CLI tool.

Changes:
- completions/openai.bash: Bash completion script
- completions/openai.zsh: Zsh completion script  
- completions/openai.fish: Fish completion script
- src/openai/cli/_completions.py: Completion generation module

Usage:
  openai completion bash > ~/.openai-completion.bash
  openai completion zsh > ~/.openai-completion.zsh
  openai completion fish > ~/.config/fish/completions/openai.fish

Completions include:
- All subcommands (api, tools, chat, image, audio, etc.)
- Model names with descriptions
- Voice options for TTS
- Image sizes and quality options
- All CLI flags and options

Fixes openai#843
Add shell auto-completion support for the openai CLI tool.

Changes:
- completions/openai.bash: Bash completion script
- completions/openai.zsh: Zsh completion script  
- completions/openai.fish: Fish completion script
- src/openai/cli/_completions.py: Completion generation module

Usage:
  openai completion bash > ~/.openai-completion.bash
  openai completion zsh > ~/.openai-completion.zsh
  openai completion fish > ~/.config/fish/completions/openai.fish

Completions include:
- All subcommands (api, tools, chat, image, audio, etc.)
- Model names with descriptions
- Voice options for TTS
- Image sizes and quality options
- All CLI flags and options

Fixes openai#843
Add shell auto-completion support for the openai CLI tool.

Changes:
- completions/openai.bash: Bash completion script
- completions/openai.zsh: Zsh completion script  
- completions/openai.fish: Fish completion script
- src/openai/cli/_completions.py: Completion generation module

Usage:
  openai completion bash > ~/.openai-completion.bash
  openai completion zsh > ~/.openai-completion.zsh
  openai completion fish > ~/.config/fish/completions/openai.fish

Completions include:
- All subcommands (api, tools, chat, image, audio, etc.)
- Model names with descriptions
- Voice options for TTS
- Image sizes and quality options
- All CLI flags and options

Fixes openai#843
Add shell auto-completion support for the openai CLI tool.

Changes:
- completions/openai.bash: Bash completion script
- completions/openai.zsh: Zsh completion script  
- completions/openai.fish: Fish completion script
- src/openai/cli/_completions.py: Completion generation module

Usage:
  openai completion bash > ~/.openai-completion.bash
  openai completion zsh > ~/.openai-completion.zsh
  openai completion fish > ~/.config/fish/completions/openai.fish

Completions include:
- All subcommands (api, tools, chat, image, audio, etc.)
- Model names with descriptions
- Voice options for TTS
- Image sizes and quality options
- All CLI flags and options

Fixes openai#843
@lrg913427-dot lrg913427-dot requested a review from a team as a code owner May 2, 2026 14:21
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: afe5d6c3f9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +355 to +359
def register(parser: argparse.ArgumentParser) -> None:
"""Register the completion command."""
sub = parser.add_parser(
"completion",
help="Generate shell completion scripts",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Wire completion subcommand into CLI parser

The new completion command is never reachable because this module's register() function is not invoked anywhere in the CLI bootstrap path. _build_parser() in src/openai/cli/_cli.py only registers api and tools, so openai completion ... will be rejected as an unknown command and the feature introduced by this commit cannot be used.

Useful? React with 👍 / 👎.

Comment on lines +23 to +24
api_commands="chat image audio files models completions fine_tuning"
tools_commands="fine_tunes"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Generate completions for actual dotted API commands

The generated scripts advertise API subcommands like chat, image, and files, but this CLI actually registers dotted commands such as chat.completions.create, images.generate, and files.create. As a result, completion suggestions steer users toward invalid command names and option matching branches (e.g. chat-specific flags) never trigger for real commands, so completions are effectively broken for the API surface.

Useful? React with 👍 / 👎.

- 171 tests covering bash, zsh, and fish completion scripts
- Test COMPLETION_SCRIPTS dict structure (3 tests)
- Test bash completion: function, registration, subcommands, models, voices, sizes, flags (43 tests)
- Test zsh completion: compdef, function, subcommands, models, voices, sizes, qualities, styles, formats, purposes, options (64 tests)
- Test fish completion: complete syntax, subcommands, models, voices, sizes, qualities, styles, options (52 tests)
- Test cross-shell consistency for models/voices/sizes/subcommands (4 tests)
- Test register() CLI argument parsing: all shells, output flag, invalid shell (6 tests)
- Test run() stdout/file output and instructions for all shells (10 tests)
- Test model list completeness: GPT-4, reasoning, image, audio families (6 tests)
- Test script syntax: brace matching, trailing whitespace, newlines (5 tests)
- Test option presence in detailed scripts: stream, temperature, max-tokens, prompt (4 tests)
- Fix missing 'import sys' in _completions.py (used by run() for stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add shell auto completion for different shell, like bash, zsh, fish, powershell

1 participant