A tool to generate comprehensive Zsh completion scripts for the Google Cloud CLI (gcloud).
This project automates the creation of Zsh tab-completion for gcloud commands by crawling the CLI's metadata. It generates a _gcloud completion script that supports nested subcommands and descriptions, enabling efficient command-line usage.
- Extracts command tree and flags from gcloud CLI metadata
- Generates recursive Zsh completion with descriptions
- Automated weekly updates via CI/CD
- No external dependencies (uses Python standard library)
- Python 3.x
- Google Cloud CLI (gcloud) installed and authenticated
-
Clone this repository:
git clone https://github.com/yourusername/gcloud-zsh-complete.git cd gcloud-zsh-complete -
Ensure gcloud CLI is installed (see official docs).
-
Run the crawler to extract gcloud metadata:
python generate_json_from_gcloud_cli.py
This creates
gcloud_completions.json. -
Generate the Zsh completion script:
python generate_zsh_from_json.py gcloud_completions.json _gcloud
-
Source the completion in your Zsh shell:
source _gcloudOr add it to your
.zshrcfor permanent loading.
The GitHub Actions workflow runs weekly (Sundays) to generate and release updated completions. Releases are tagged with the gcloud CLI version (e.g., 123.0.0) and include the _gcloud file as an asset.
The generated completions are based on the gcloud CLI metadata accessible under the authenticated account used during generation. This may not include all possible commands if certain components or permissions are restricted. The released versions reflect the latest automated run and might not cover everything. However, the pipeline defaults still cover most command combinations and custom runs are not required in most cases. For comprehensive completions tailored to your account, run the scripts manually: first python generate_json_from_gcloud_cli.py to extract metadata, then python generate_zsh_from_json.py gcloud_completions.json _gcloud to generate the script.
Contributions are welcome! Please open issues or pull requests for improvements.
This project is licensed under the MIT License. See LICENSE file for details.