// ZSH-GEM-COMPLETION — LIVE REMOTE GEM COMPLETION FOR gem install

zsh plugin · all OMZ gem completion · plus live gem search-backed completer for gem install

GitHub Issues
// Color scheme

>_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_search shells out to gem search -q $PREFIX and renders the rubygems.org results with descriptions.
  • Local completion for uninstall / update / list__gem_installed reads gem 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_cache store keyed gem_${PREFIX}_cache.
  • 3 publishing shortcutsgemb, gemp, and the gemy function 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.

buildBuild a gem from a gemspec
certManage RubyGems certificates and signing settings
checkCheck a gem repository for added or missing files
cleanupClean up old versions of installed gems in the local repository
contentsDisplay the contents of the installed gems
dependencyShow the dependencies of an installed gem
environmentDisplay information about the RubyGems environment
fetchDownload a gem and place it in the current directory
generate_indexGenerates the index files for a gem server directory
helpProvide help on the gem command
installInstall a gem into the local repository
listDisplay gems whose name starts with STRING
lockGenerate a lockdown list of gems
mirrorMirror all gem files (requires rubygems-mirror)
outdatedDisplay all gems that need updates
ownerManage gem owners on RubyGems.org.
pristineRestores installed gems to pristine condition from files located in the gem cache
pushPush a gem up to RubyGems.org
queryQuery gem information in local or remote repositories
rdocGenerates RDoc for pre-installed gems
searchDisplay all gems whose name contains STRING
serverDocumentation and gem repository HTTP server
sourcesManage the sources and cache file RubyGems uses to search for gems
specificationDisplay gem specification (in yaml)
staleList gems along with access times
uninstallUninstall gems from the local repository
unpackUnpack an installed gem to the current directory
updateUpdate installed gems to the latest version
whichFind the location of a library file you can require
yankRemove 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_searchgem search -q $PREFIX → parse name version_describe -t remote-gem.
gem uninstall <TAB>Local: __gem_installedgem 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:

gembalias gemb="gem build *.gemspec" — build the gemspec in the current directory.
gempalias gemp="gem push *.gem" — push the freshly-built .gem tarball.
gemy GEM VERfunction 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 allEnsure 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 / emptyThe 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 resultsRemote 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 gemsIt 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: