_gem
2571 bytes
1#compdef gem
2#autoload
3
4# gem zsh completion, based on homebrew completion
5
6_gem_installed() {
7 installed_gems=(${(f)"$(gem list --local --no-versions)"})
8}
9
10local -a _1st_arguments
11
12_1st_arguments=(
13 'build:Build a gem from a gemspec'
14 'cert:Manage RubyGems certificates and signing settings'
15 'check:Check a gem repository for added or missing files'
16 'cleanup:Clean up old versions of installed gems in the local repository'
17 'contents:Display the contents of the installed gems'
18 'dependency:Show the dependencies of an installed gem'
19 'environment:Display information about the RubyGems environment'
20 'fetch:Download a gem and place it in the current directory'
21 'generate_index:Generates the index files for a gem server directory'
22 'help:Provide help on the `gem` command'
23 'install:Install a gem into the local repository'
24 'list:Display gems whose name starts with STRING'
25 'lock:Generate a lockdown list of gems'
26 'mirror:Mirror all gem files (requires rubygems-mirror)'
27 'outdated:Display all gems that need updates'
28 'owner:Manage gem owners on RubyGems.org.'
29 'pristine:Restores installed gems to pristine condition from files located in the gem cache'
30 'push:Push a gem up to RubyGems.org'
31 'query:Query gem information in local or remote repositories'
32 'rdoc:Generates RDoc for pre-installed gems'
33 'search:Display all gems whose name contains STRING'
34 'server:Documentation and gem repository HTTP server'
35 'sources:Manage the sources and cache file RubyGems uses to search for gems'
36 'specification:Display gem specification (in yaml)'
37 'stale:List gems along with access times'
38 'uninstall:Uninstall gems from the local repository'
39 'unpack:Unpack an installed gem to the current directory'
40 'update:Update installed gems to the latest version'
41 'which:Find the location of a library file you can require'
42 'yank:Remove a specific gem version release from RubyGems.org'
43)
44
45local expl
46local -a gems installed_gems
47
48_arguments \
49 '(-v --version)'{-v,--version}'[show version]' \
50 '(-h --help)'{-h,--help}'[show help]' \
51 '*:: :->subcmds' && return 0
52
53if (( CURRENT == 1 )); then
54 _describe -t commands "gem subcommand" _1st_arguments
55 return
56fi
57
58case "$words[1]" in
59 build)
60 _files -g "*.gemspec"
61 ;;
62 install)
63 _files ;;
64 list)
65 if [[ "$state" == forms ]]; then
66 _gem_installed
67 _requested installed_gems expl 'installed gems' compadd -a installed_gems
68 fi ;;
69 uninstall|update)
70 _gem_installed
71 _wanted installed_gems expl 'installed gems' compadd -a installed_gems ;;
72esac