bundler-exec.plugin.zsh 756 Bytes
Newer Older
Bodo Tasche's avatar
Bodo Tasche committed
1
# This plugin is based on https://github.com/gma/bundler-exec
Bodo Tasche's avatar
Bodo Tasche committed
2
# modify the bundled_commands if needed
Bodo Tasche's avatar
Bodo Tasche committed
3

Hakan Ensari's avatar
Hakan Ensari committed
4
bundled_commands=(cap capify cucumber heroku rackup rails rake rspec ruby shotgun spec spork thin unicorn unicorn_rails)
Bodo Tasche's avatar
Bodo Tasche committed
5
6
7

## Functions

Bodo Tasche's avatar
Bodo Tasche committed
8
_bundler-installed() {
Hakan Ensari's avatar
Hakan Ensari committed
9
  which bundle > /dev/null 2>&1
Bodo Tasche's avatar
Bodo Tasche committed
10
11
}

Bodo Tasche's avatar
Bodo Tasche committed
12
_within-bundled-project() {
Hakan Ensari's avatar
Hakan Ensari committed
13
14
15
16
17
18
  local check_dir=$PWD
  while [ "$(dirname $check_dir)" != "/" ]; do
    [ -f "$check_dir/Gemfile" ] && return
    check_dir="$(dirname $check_dir)"
  done
  false
Bodo Tasche's avatar
Bodo Tasche committed
19
20
}

Bodo Tasche's avatar
Bodo Tasche committed
21
_run-with-bundler() {
Hakan Ensari's avatar
Hakan Ensari committed
22
23
24
25
26
27
28
  local command="$1"
  shift
  if _bundler-installed && _within-bundled-project; then
    bundle exec $command "$@"
  else
    $command "$@"
  fi
Bodo Tasche's avatar
Bodo Tasche committed
29
30
31
}

## Main program
Bodo Tasche's avatar
Bodo Tasche committed
32
for cmd in $bundled_commands; do
Hakan Ensari's avatar
Hakan Ensari committed
33
  alias $cmd="_run-with-bundler $cmd"
Bodo Tasche's avatar
Bodo Tasche committed
34
done