Get the latest tech news

Writing simple tab-completions for Bash and Zsh


Li Haoyi, 7 August 2025 Shell tab-completions can be very handy, but setting them up is complicated by the fact that half your users would be using Bash-on-Linux, while the other half will be using Zsh-on-OSX, each of which has different tab-completion APIs. Furthermore, most users exploring an unfamiliar CLI tool using tab completion appreciate showing a description along with each completion so they can read what it is, but that’s normally only available on Zsh and not on Bash.

Tab-completion is a common way to explore unfamiliar APIs, and just because someone finished writing a flat or command doesn’t mean they aren’t curious about what it does! To solve this, we can hack Bash and Zsh to print tab-completion descriptions even if the token is already a complete word. But because Zsh expects to pass two parallel arrays of descriptions and tokens to compadd, our if block needs to append items to both trimmed and raw.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Bash

Bash

Photo of zsh

zsh

Photo of completions

completions

Related news:

News photo

Getting decent error reports in Bash when you're using 'set -e'

News photo

Red Hat Has Been Rewriting Bash-Based Greenboot In Rust

News photo

Debugging Bash Like a Sire (2023)