89278c71b2c3fe6b98db1d22d8ca742447aae406
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/bundler/bundler.plugin.zsh b/plugins/bundler/bundler.plugin.zsh
2index 65b0ffa6e0c5e564c0f62d328361fe41c008f9b7..6293dc28aee0da689cb37e849c1801d009ce7e97 100644
3--- a/plugins/bundler/bundler.plugin.zsh
4+++ b/plugins/bundler/bundler.plugin.zsh
5@@ -1,13 +1,49 @@
6+## Aliases
7+
8 alias ba="bundle add"
9+alias bck="bundle check"
10+alias bcn="bundle clean"
11 alias be="bundle exec"
12+alias bi="bundle_install"
13 alias bl="bundle list"
14-alias bp="bundle package"
15 alias bo="bundle open"
16 alias bout="bundle outdated"
17+alias bp="bundle package"
18 alias bu="bundle update"
19-alias bi="bundle_install"
20-alias bcn="bundle clean"
21-alias bck="bundle check"
22+
23+## Functions
24+
25+bundle_install() {
26+ # Bail out if bundler is not installed
27+ if (( ! $+commands[bundle] )); then
28+ echo "Bundler is not installed"
29+ return 1
30+ fi
31+
32+ # Bail out if not in a bundled project
33+ if ! _within-bundled-project; then
34+ echo "Can't 'bundle install' outside a bundled project"
35+ return 1
36+ fi
37+
38+ # Check the bundler version is at least 1.4.0
39+ autoload -Uz is-at-least
40+ local bundler_version=$(bundle version | cut -d' ' -f3)
41+ if ! is-at-least 1.4.0 "$bundler_version"; then
42+ bundle install "$@"
43+ return $?
44+ fi
45+
46+ # If bundler is at least 1.4.0, use all the CPU cores to bundle install
47+ if [[ "$OSTYPE" = (darwin|freebsd)* ]]; then
48+ local cores_num="$(sysctl -n hw.ncpu)"
49+ else
50+ local cores_num="$(nproc)"
51+ fi
52+ bundle install --jobs="$cores_num" "$@"
53+}
54+
55+## Gem wrapper
56
57 bundled_commands=(
58 annotate
59@@ -54,65 +90,41 @@ for cmd in $BUNDLED_COMMANDS; do
60 bundled_commands+=($cmd);
61 done
62
63-## Functions
64-
65-bundle_install() {
66- if ! _bundler-installed; then
67- echo "Bundler is not installed"
68- elif ! _within-bundled-project; then
69- echo "Can't 'bundle install' outside a bundled project"
70- else
71- local bundler_version=`bundle version | cut -d' ' -f3`
72- if [[ $bundler_version > '1.4.0' || $bundler_version = '1.4.0' ]]; then
73- if [[ "$OSTYPE" = (darwin|freebsd)* ]]
74- then
75- local cores_num="$(sysctl -n hw.ncpu)"
76- else
77- local cores_num="$(nproc)"
78- fi
79- bundle install --jobs=$cores_num $@
80- else
81- bundle install $@
82- fi
83- fi
84-}
85-
86-_bundler-installed() {
87- which bundle > /dev/null 2>&1
88-}
89-
90+# Check if in the root or a subdirectory of a bundled project
91 _within-bundled-project() {
92 local check_dir="$PWD"
93- while [ "$check_dir" != "/" ]; do
94- [ -f "$check_dir/Gemfile" -o -f "$check_dir/gems.rb" ] && return
95- check_dir="$(dirname $check_dir)"
96+ while [[ "$check_dir" != "/" ]]; do
97+ if [[ -f "$check_dir/Gemfile" || -f "$check_dir/gems.rb" ]]; then
98+ return 0
99+ fi
100+ check_dir="${check_dir:h}"
101 done
102- false
103-}
104-