Skip to content

Commit

Permalink
Adds zsh completions
Browse files Browse the repository at this point in the history
  • Loading branch information
pengwynn committed Apr 14, 2012
1 parent 15b931d commit ad10376
Show file tree
Hide file tree
Showing 6 changed files with 1,249 additions and 0 deletions.
82 changes: 82 additions & 0 deletions zsh/functions/_bundler
@@ -0,0 +1,82 @@
#compdef bundle

local curcontext="$curcontext" state line _gems _opts ret=1

_arguments -C -A "-v" -A "--version" \
'(- 1 *)'{-v,--version}'[display version information]' \
'1: :->cmds' \
'*:: :->args' && ret=0

case $state in
cmds)
_values "bundle command" \
"install[Install the gems specified by the Gemfile or Gemfile.lock]" \
"update[Update dependencies to their latest versions]" \
"package[Package the .gem files required by your application]" \
"exec[Execute a script in the context of the current bundle]" \
"config[Specify and read configuration options for bundler]" \
"check[Determine whether the requirements for your application are installed]" \
"list[Show all of the gems in the current bundle]" \
"show[Show the source location of a particular gem in the bundle]" \
"console[Start an IRB session in the context of the current bundle]" \
"open[Open an installed gem in the editor]" \
"viz[Generate a visual representation of your dependencies]" \
"init[Generate a simple Gemfile, placed in the current directory]" \
"gem[Create a simple gem, suitable for development with bundler]" \
"help[Describe available tasks or one specific task]"
ret=0
;;
args)
case $line[1] in
help)
_values 'commands' \
'install' \
'update' \
'package' \
'exec' \
'config' \
'check' \
'list' \
'show' \
'console' \
'open' \
'viz' \
'init' \
'gem' \
'help' && ret=0
;;
install)
_arguments \
'(--no-color)--no-color[disable colorization in output]' \
'(--local)--local[do not attempt to connect to rubygems.org]' \
'(--quiet)--quiet[only output warnings and errors]' \
'(--gemfile)--gemfile=-[use the specified gemfile instead of Gemfile]:gemfile' \
'(--system)--system[install to the system location]' \
'(--deployment)--deployment[install using defaults tuned for deployment environments]' \
'(--frozen)--frozen[do not allow the Gemfile.lock to be updated after this install]' \
'(--path)--path=-[specify a different path than the system default]:path:_files' \
'(--binstubs)--binstubs=-[generate bin stubs for bundled gems to ./bin]:directory:_files' \
'(--without)--without=-[exclude gems that are part of the specified named group]:groups'
ret=0
;;
exec)
_normal && ret=0
;;
(open|show)
_gems=( $(bundle show 2> /dev/null | sed -e '/^ \*/!d; s/^ \* \([^ ]*\) .*/\1/') )
if [[ $_gems != "" ]]; then
_values 'gems' $_gems && ret=0
fi
;;
*)
_opts=( $(bundle help $line[1] | sed -e '/^ \[-/!d; s/^ \[\(-[^=]*\)=.*/\1/') )
_opts+=( $(bundle help $line[1] | sed -e '/^ -/!d; s/^ \(-.\), \[\(-[^=]*\)=.*/\1 \2/') )
if [[ $_opts != "" ]]; then
_values 'options' $_opts && ret=0
fi
;;
esac
;;
esac

return ret
64 changes: 64 additions & 0 deletions zsh/functions/_gem
@@ -0,0 +1,64 @@
#compdef gem
#autoload

# gem zsh completion, based on homebrew completion

_gem_installed() {
installed_gems=(`gem list --local --no-versions`)
}

local -a _1st_arguments
_1st_arguments=(
'cert:Manage RubyGems certificates and signing settings'
'check:Check installed gems'
'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 a gem repository'
'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 the named gems (or all installed gems) in the local repository'
'which:Find the location of a library file you can require'
)

local expl
local -a gems installed_gems

_arguments \
'(-v --version)'{-v,--version}'[show version]' \
'(-h --help)'{-h,--help}'[show help]' \
'*:: :->subcmds' && return 0

if (( CURRENT == 1 )); then
_describe -t commands "gem subcommand" _1st_arguments
return
fi

case "$words[1]" in
list)
if [[ "$state" == forms ]]; then
_gem_installed
_requested installed_gems expl 'installed gems' compadd -a installed_gems
fi ;;
uninstall|update)
_gem_installed
_wanted installed_gems expl 'installed gems' compadd -a installed_gems ;;
esac

0 comments on commit ad10376

Please sign in to comment.