>_ZSH-GEM-COMPLETION
gem install <TAB> queries the remote index. All functionality of the OMZ gem completion plus a live gem search-backed completer for gem install.
Overview
zsh-gem-completion is a single #compdef gem completion (src/_gem) plus a small plugin entrypoint (zsh-gem-completion.plugin.zsh). It started from the Homebrew/OMZ gem completion and adds one behavior the upstream lacks: gem install <TAB> completes remote gems from the live output of gem search, not just gems already installed locally.
- 30 subcommands with one-line man-page descriptions, offered when you type
gem <TAB>. - Remote completion for
install—__gem_searchshells out togem search -q $PREFIXand renders the rubygems.org results with descriptions. - Local completion for
uninstall/update/list—__gem_installedreadsgem list --local --no-versions. - File completion for
build—_files -g "*.gemspec", glob-restricted to gemspecs. - Two-tier cache — an in-shell array (
__gems_${PREFIX}) and the on-disk_store_cache/_retrieve_cachestore keyedgem_${PREFIX}_cache. - 3 publishing shortcuts —
gemb,gemp, and thegemyfunction for the gem-author build/push/yank loop.
Requires zsh, the zsh completion system (compinit), and the gem command on $PATH. The remote-search path additionally relies on gem search reaching rubygems.org.
Install
# Zinit
zinit ice lucid nocompile
zinit load MenkeTechnologies/zsh-gem-completion
# Oh My Zsh
git clone https://github.com/MenkeTechnologies/zsh-gem-completion \
"$HOME/.oh-my-zsh/custom/plugins/zsh-gem-completion"
# then: plugins+=(zsh-gem-completion)
# Manual
git clone https://github.com/MenkeTechnologies/zsh-gem-completion
source zsh-gem-completion/zsh-gem-completion.plugin.zsh
Examples
gem <TAB> # subcommand completion (30 entries, with descriptions) gem install <TAB> # live remote gem name completion via `gem search` gem install ra<TAB> # remote search for the `ra` prefix: rails, rack, rake, ... gem uninstall <TAB> # locally-installed gems only (gem list --local --no-versions) gem update <TAB> # locally-installed gems only gem list <TAB> # locally-installed gems (in the `forms` state) gem build <TAB> # *.gemspec files in the current directory gemb # gem build *.gemspec gemp # gem push *.gem gemy my-gem 1.2.3 # gem yank my-gem -v 1.2.3
First TAB on a remote prefix pays one gem search network round-trip; subsequent TABs for the same prefix are served from cache — the in-shell array within the session, and the on-disk store across sessions.
Subcommand reference
Every entry in _1st_arguments (src/_gem), offered on gem <TAB>. Descriptions are the exact strings shown in the completion menu.
| build | Build a gem from a gemspec |
| cert | Manage RubyGems certificates and signing settings |
| check | Check a gem repository for added or missing files |
| cleanup | Clean up old versions of installed gems in the local repository |
| contents | Display the contents of the installed gems |
| dependency | Show the dependencies of an installed gem |
| environment | Display information about the RubyGems environment |
| fetch | Download a gem and place it in the current directory |
| generate_index | Generates the index files for a gem server directory |
| help | Provide help on the gem command |
| install | Install a gem into the local repository |
| list | Display gems whose name starts with STRING |
| lock | Generate a lockdown list of gems |
| mirror | Mirror all gem files (requires rubygems-mirror) |
| outdated | Display all gems that need updates |
| owner | Manage gem owners on RubyGems.org. |
| pristine | Restores installed gems to pristine condition from files located in the gem cache |
| push | Push a gem up to RubyGems.org |
| query | Query gem information in local or remote repositories |
| rdoc | Generates RDoc for pre-installed gems |
| search | Display all gems whose name contains STRING |
| server | Documentation and gem repository HTTP server |
| sources | Manage the sources and cache file RubyGems uses to search for gems |
| specification | Display gem specification (in yaml) |
| stale | List gems along with access times |
| uninstall | Uninstall gems from the local repository |
| unpack | Unpack an installed gem to the current directory |
| update | Update installed gems to the latest version |
| which | Find the location of a library file you can require |
| yank | Remove a specific gem version release from RubyGems.org |
Top-level flags, offered before a subcommand is chosen: -v/--version (show version) and -h/--help (show help), each declared mutually-exclusive with its long form.
Completion behavior
After the top-level _arguments dispatch, src/_gem branches per first word. Only these subcommands have argument completion wired; the rest complete the subcommand name only.
| gem <TAB> | Lists all 30 subcommands with descriptions (_describe -t commands). |
| gem install <TAB> | Remote search: __gem_search → gem search -q $PREFIX → parse name version → _describe -t remote-gem. |
| gem uninstall <TAB> | Local: __gem_installed → gem list --local --no-versions → _wanted installed_gems. |
| gem update <TAB> | Local: same __gem_installed path as uninstall. |
| gem list <TAB> | Local installed gems, requested via _requested installed_gems (forms state). |
| gem build <TAB> | Files: _files -g "*.gemspec" — gemspecs only. |
Remote-search parse + quoting: each line of gem search output is read as tag desc (gem name, then the remainder of the line), then stored as ${(q)tag}:${(q)desc}. The (q) flag backslash-quotes both halves so colons or spaces in the name/version don't mis-split zsh's name:description tuple. __gem_search is the active dispatcher; __gem_search_mem is the in-shell-array variant kept in the source as the session-cache implementation.
Aliases & functions
Registered by zsh-gem-completion.plugin.zsh for the gem-author build/push/yank loop:
| gemb | alias gemb="gem build *.gemspec" — build the gemspec in the current directory. |
| gemp | alias gemp="gem push *.gem" — push the freshly-built .gem tarball. |
| gemy GEM VER | function gemy { gem yank $1 -v $2 } — yank version VER of GEM. A function (not an alias) so the two positional args are passed in order. |
Configuration
The completion sets one zstyle in src/_gem:
zstyle ':completion:*:*:gem:*:remote-gem' list-grouped false
This scopes only the remote-search results (the remote-gem tag) and turns off description-grouping, so each remote gem renders on its own row. The local gem list path is untouched and keeps the default grouping. You can override completion presentation with your own zstyle lines after the plugin loads; the entrypoint also prepends src/ to fpath so compinit can autoload _gem.
Troubleshooting
| No completion at all | Ensure compinit runs in ~/.zshrc and that src/ is on fpath (the plugin entrypoint prepends it). With Zinit, load via zinit load MenkeTechnologies/zsh-gem-completion. |
gem install <TAB> is slow / empty | The first TAB per prefix runs gem search over the network. A slow or offline rubygems.org delays or empties results; the result is cached after the first successful hit. |
| Stale remote results | Remote results are cached on disk per prefix (gem_${PREFIX}_cache). Clear zsh's completion cache to force a fresh gem search. |
uninstall/update shows remote gems | It shouldn't — those route to __gem_installed (local only). If you see remote results, another _gem earlier on fpath is shadowing this one. |
Engineering report
For the file-by-file breakdown, completion-coverage matrix, test inventory, and design-decision notes, see the Engineering Report.
Sibling plugins
Part of the MenkeTechnologies zsh plugin family — the MenkeTechnologiesMeta umbrella:
- zsh-better-npm-completion — cache-aware
npm installcompletion - zsh-cargo-completion — live
cargo add/cargo installcompletion - zsh-cpan-completion — live MetaCPAN
cpan/cpanmcompletion - zsh-dotnet-completion — dotnet CLI completion
- zsh-expand — spacebar expansion (11,683 tests)
- zsh-git-acp — 159 git aliases + add/commit/push keybindings
- zsh-git-repo-cache — index every git repo on disk
- zsh-learn — MySQL-backed learning collection / quiz
- zsh-more-completions — 33,175-file mega completion corpus
- zsh-nginx — nginx commands + service-wrapper aliases
- zsh-pip-description-completion — pip remote completion with descriptions
- zsh-sed-sub — in-place sed substitution on the command line
- zsh-sudo — ESC ESC to prepend sudo
- zsh-xcode-completions — xcodebuild / xcrun / swift completion