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

Bodo Tasche's avatar
Bodo Tasche committed
4
bundled_commands=(cucumber heroku rackup rails rake rspec ruby shotgun spec spork)
Bodo Tasche's avatar
Bodo Tasche committed
5
6
7

## Functions

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

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

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

## Main program
Bodo Tasche's avatar
Bodo Tasche committed
35
for cmd in $bundled_commands; do
36
   alias $cmd="_run-with-bundler $cmd"
Bodo Tasche's avatar
Bodo Tasche committed
37
done