Skip to content
Browse files

New zsh completion workflow

  • Loading branch information...
1 parent e9c6903 commit 04a7bd347e80abef7b159a196ea8bb36c20843a7 @jferris committed
Showing with 87 additions and 73 deletions.
  1. +0 −73 zlogin
  2. +69 −0 zsh/completion/_bundler
  3. +3 −0 zsh/completion/_cucumber
  4. +3 −0 zsh/completion/_rspec
  5. +12 −0 zshrc
View
73 zlogin
@@ -18,76 +18,3 @@ setopt prompt_subst
# prompt
export PS1='$(git_prompt_info)[${SSH_CONNECTION+"%{$fg_bold[green]%}%n@%m:"}%{$fg_bold[blue]%}%~%{$reset_color%}] '
-# autocompletion for ruby_test
-# works with tu/tf aliases
-_ruby_tests() {
- if [[ -n $words[2] ]]; then
- compadd `ruby_test -l ${words[2]}`
- fi
-}
-compdef _ruby_tests ruby_test
-
-# autocompletion for ruby_spec
-# works with sm/sc aliases
-_ruby_specs() {
- if [[ -n $words[2] ]]; then
- compadd `ruby_spec -l ${words[2]}`
- fi
-}
-compdef _ruby_specs ruby_spec
-
-# autocompletion for ruby_tu_rs
-# works with su/sf aliases
-_ruby_mixed_tests() {
- if [[ -n $words[2] ]]; then
- compadd `ruby_tu_rs -l ${words[2]}`
- fi
-}
-compdef _ruby_mixed_tests ruby_tu_rs
-
-_git_remote_branch() {
- ref=$(git symbolic-ref HEAD 2> /dev/null)
- if [[ -n $ref ]]; then
- if (( CURRENT == 2 )); then
- # first arg: operation
- compadd track remote_add remote_rm rm push mv new pull
- elif (( CURRENT == 3 )); then
- if [[ $words[2] == "push" ]]; then
- # second arg: local branch name
- compadd `git branch -l | sed "s/[ \*]//g"`
- else;
- # second arg: remote branch name
- compadd `git branch -r | grep -v HEAD | sed "s/.*\///" | sed "s/ //g"`
- fi
- elif (( CURRENT == 4 )); then
- # third arg: remote name
- compadd `git remote`
- fi
- else;
- _files
- fi
-}
-compdef _git_remote_branch grb
-
-# autocompletion for schema
-_rails_tables() {
- if [[ -n $words[2] ]]; then
- compadd `schema -l ${words[2]}`
- fi
-}
-compdef _rails_tables schema
-
-# autocompletion for cuc
-_cucumber_features() {
- compadd `ls features/**/*.feature | sed "s/features\/\(.*\).feature/\1/"`
-}
-compdef _cucumber_features cuc
-
-# restore previous cwd
-if [[ -f ~/.last_cwd ]]; then
- cd `cat ~/.last_cwd`
-fi
-_save_last_cwd() {
- echo `pwd` > ~/.last_cwd
-}
-chpwd_functions=( "${chpwd_functions[@]}" _save_last_cwd )
View
69 zsh/completion/_bundler
@@ -0,0 +1,69 @@
+#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
+
View
3 zsh/completion/_cucumber
@@ -0,0 +1,3 @@
+#compdef cucumber
+
+compadd -P features/ -S .feature `ls features/**/*.feature | sed -E "s/features\/|\.feature//g"`
View
3 zsh/completion/_rspec
@@ -0,0 +1,3 @@
+#compdef rspec
+
+compadd -P spec/ -S _spec.rb `ls spec/**/*_spec.rb | sed -E "s/spec\/|_spec\.rb//g"`
View
12 zshrc
@@ -1,3 +1,5 @@
+fpath=(~/.zsh/completion $fpath)
+
# completion
autoload -U compinit
compinit
@@ -15,6 +17,7 @@ fi
# vi mode
bindkey -v
+bindkey ^F vi-cmd-mode
# use incremental search
bindkey ^R history-incremental-search-backward
@@ -34,3 +37,12 @@ export HISTSIZE=200
# look for ey config in project dirs
export EYRC=./.eyrc
+# restore previous cwd
+if [[ -f ~/.last_cwd ]]; then
+ cd `cat ~/.last_cwd`
+fi
+_save_last_cwd() {
+ echo `pwd` > ~/.last_cwd
+}
+chpwd_functions=( "${chpwd_functions[@]}" _save_last_cwd )
+

0 comments on commit 04a7bd3

Please sign in to comment.
Something went wrong with that request. Please try again.