From 73c940356ee16826ff9f550a79e6683f0017123d Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 13 Jan 2012 09:18:34 +0100 Subject: [PATCH] bundler support --- zshrc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/zshrc b/zshrc index 7c8337b..f959fef 100644 --- a/zshrc +++ b/zshrc @@ -48,6 +48,40 @@ HISTFILE=~/.zsh_history autoload -Uz compinit compinit +# bundler +bundled_commands=(annotate cap capify cucumber foreman guard heroku nanoc rackup rainbows rake rspec ruby shotgun spec spork thin unicorn unicorn_rails irb rails) + +_bundler-installed() { + which bundle > /dev/null 2>&1 +} + +_within-bundled-project() { + local check_dir=$PWD + while [ "$(dirname $check_dir)" != "/" ]; do + [ -f "$check_dir/Gemfile" ] && return + check_dir="$(dirname $check_dir)" + done + false +} + +_run-with-bundler() { + if _bundler-installed && _within-bundled-project; then + bundle exec $@ + else + $@ + fi +} + +## Main program +for cmd in $bundled_commands; do + eval "function bundled_$cmd () { _run-with-bundler $cmd \$@}" + alias $cmd=bundled_$cmd + + if which _$cmd > /dev/null 2>&1; then + compdef _$cmd bundled_$cmd=$cmd + fi +done + # git completion speed boost __git_files () { _wanted files expl 'local files' _files