1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #!/bin/bash
- # Automatically run Ruby scripts with "bundle exec" (but only when appropriate).
- # http://effectif.com/ruby/automating-bundle-exec
- # Github: https://github.com/gma/bundler-exec
- ## Functions
- bundler-installed()
- {
- which bundle > /dev/null 2>&1
- }
- within-bundled-project()
- {
- local dir="$(pwd)"
- while [ "$(dirname $dir)" != "/" ]; do
- [ -f "$dir/Gemfile" ] && return
- dir="$(dirname $dir)"
- done
- false
- }
- run-with-bundler()
- {
- if bundler-installed && within-bundled-project; then
- bundle exec "$@"
- else
- "$@"
- fi
- }
- define-bundler-aliases()
- {
- # Allow zsh to iterate over list of words
- [ -n "$ZSH_VERSION" ] && setopt localoptions shwordsplit
- local command
- for command in $BUNDLED_COMMANDS; do
- if [[ $command != "bundle" && $command != "gem" ]]; then
- alias $command="run-with-bundler $command"
- fi
- done
- }
- ## Main program
- BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
- cap
- capify
- chef
- chefspec
- chef-apply
- chef-client
- chef-shell
- chef-solo
- cucumber
- foodcritic
- foreman
- guard
- haml
- html2haml
- jasmine
- jekyll
- kitchen
- knife
- middleman
- pry
- rackup
- rake
- rake2thor
- rspec
- ruby
- sass
- sass-convert
- serve
- shotgun
- spec
- spork
- strainer
- thin
- thor
- tilt
- tt
- turn
- unicorn
- unicorn_rails
- wagon
- }"
- define-bundler-aliases
- unset -f define-bundler-aliases
|