Skip to content
Back to Insights
Data EngineeringBy KE Engineering Team

KZSH: Kafka Autocomplete

KZSH: Kafka AutocompleteDATA ENGINEERING cover for KZSH: Kafka Autocomplete$ kafka-topics --describe --topic ordordersorders.dlqorders.enrichedTAB · 3 TOPICS FROM THE BROKERDATA ENGINEERINGKZSH: KafkaAutocomplete// TYPE LESS · OPERATE FASTER

First written September 2024, last updated September 2026.

Introduction

Kafka's CLI tools have dozens of flags, and topic names have to be typed exactly. These Z-Shell completions fix both. They're in the kzsh-autocomplete repo, along with an optional CLI command kaflist that can be natively compiled with GraalVM for a faster autocomplete experience when topics, groups, and principals are fetched from the broker.

Please see README.md for complete setup instructions.

Autocomplete Structure

Many Apache Kafka CLI tools have sub-commands, even though they look like arguments. For example, kafka-topics has --list and --create, which can't be used together but can be placed anywhere in the command line argument list. These autocomplete scripts rely on those arguments appearing early in the command, since they control which additional arguments can then be used. The CLI tools themselves don't require that order; the scripts do, so they never present options that don't apply to the sub-command you've chosen.

The connection configurations of --bootstrap-server and the various config arguments (e.g. --command-config) must exist before the topics, groups, and principals lookups can be done, since they are required for connecting to the Kafka cluster. Lookups of principals are only available by installing the kaflist GraalVM compiled utility.

These autocomplete scripts are lazy-loaded on first use, following the Z-Shell naming convention (_command) and placing them in the Z-Shell’s function path, $fpath.

Currently Supported Apache CLI Commands

  • kafka-topics
  • kafka-consumer-groups
  • kafka-console-producer
  • kafka-console-consumer
  • kafka-configs

kafka-topics

Fig. 1: kafka-topics autocomplete

Once --bootstrap-server and the optional --command-config are provided, --topic can autocomplete the actual list of topics available on the cluster. This greatly reduces typing mistakes and the need to copy and paste.

This command has five sub-commands (--list, --create, --alter, --delete, and --describe), each having additional allowed arguments.

kafka-consumer-groups

Fig. 2: kafka-consumer-groups autocomplete

Once --bootstrap-server and the optional --command-config are provided, in addition to autocomplete of --topic, --group can autocomplete the actual list of groups available in the cluster.

This command has five sub-commands (--list, --describe, --delete, --reset-offsets, and --delete-offsets), each having additional allowed arguments.

kafka-console-producer

Fig. 3: kafka-console-producer autocomplete

The console producer has a lot of options; let the Z-Shell autocomplete help you select the topic, as well as all the possible configuration properties.

kafka-console-consumer

Fig. 4: kafka-console-consumer autocomplete

Like the console producer, the consumer has many options. In addition to selecting the topic (and optional group), let the autocomplete help with property selection as well as deserializers.

kafka-configs

Adjust the configuration of a Kafka resource. The kafka-configs command is rather complex, so the autocomplete may show its limitations (e.g. using --clients and --users concurrently).

Update to the latest kaflist for support of broker IDs, IPs, and clients in the autocomplete.

Troubleshooting

  • Be sure to set your fpath prior to enabling compinit in your .zshrc file.
shell
fpath=(~/.zsh/functions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.9/functions)autoload -Uz compinit && compinit
  • If newly added autocomplete scripts aren't working, either exit your shell and create a new one, or try rehash. This command updates the shell’s internal hash tables of executables.
  • Updating a script

If you update a script provided in this project, to reload it successfully within your current shell, do the following (adjusting to where you are placing the functions):

shell
cp ./functions/_kafka-topics ~/.zsh/functionsunfunction _kafka-topicsautoload -Uz _kafka-topics

Working on something like this?

Start a Conversation