summaryrefslogtreecommitdiff
path: root/plugins/bundler
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/bundler')
-rw-r--r--plugins/bundler/README.md49
-rw-r--r--plugins/bundler/_bundler13
-rw-r--r--plugins/bundler/bundler.plugin.zsh80
3 files changed, 135 insertions, 7 deletions
diff --git a/plugins/bundler/README.md b/plugins/bundler/README.md
new file mode 100644
index 000000000..56f0c7176
--- /dev/null
+++ b/plugins/bundler/README.md
@@ -0,0 +1,49 @@
+# Bundler
+
+- adds completion for basic bundler commands
+- adds short aliases for common bundler commands
+ - `be` aliased to `bundle exec`
+ - `bl` aliased to `bundle list`
+ - `bp` aliased to `bundle package`
+ - `bo` aliased to `bundle open`
+ - `bu` aliased to `bundle update`
+ - `bi` aliased to `bundle install --jobs=<cpu core count>` (only for bundler `>= 1.4.0`)
+- adds a wrapper for common gems:
+ - looks for a binstub under `./bin/` and executes it (if present)
+ - calls `bundle exec <gem executable>` otherwise
+
+For a full list of *common gems* being wrapped by default please look at the `bundler.plugin.zsh` file.
+
+## Configuration
+
+Please use the exact name of the executable and not the gem name.
+
+### Add additional gems to be wrapped
+
+Add this before the plugin-list in your `.zshrc`:
+```sh
+BUNDLED_COMMANDS=(rubocop)
+plugins=(... bundler ...)
+```
+This will add the wrapper for the `rubocop` gem (i.e. the executable).
+
+
+### Exclude gems from being wrapped
+
+Add this before the plugin-list in your `.zshrc`:
+```sh
+UNBUNDLED_COMMANDS=(foreman spin)
+plugins=(... bundler ...)
+```
+This will exclude the `foreman` and `spin` gems (i.e. their executable) from being wrapped.
+
+## Excluded gems
+
+These gems should not be called with `bundle exec`. Please see the Issues on GitHub for clarification.
+
+`berks`
+`foreman`
+`mailcatcher`
+`rails`
+`ruby`
+`spin`
diff --git a/plugins/bundler/_bundler b/plugins/bundler/_bundler
index 2ec3a5f9c..ba647ab80 100644
--- a/plugins/bundler/_bundler
+++ b/plugins/bundler/_bundler
@@ -18,11 +18,13 @@ case $state in
"check[Determine whether the requirements for your application are installed]" \
"list[Show all of the gems in the current bundle]" \
"show[Show the source location of a particular gem in the bundle]" \
+ "outdated[Show all of the outdated gems in the current bundle]" \
"console[Start an IRB session in the context of the current bundle]" \
"open[Open an installed gem in the editor]" \
"viz[Generate a visual representation of your dependencies]" \
"init[Generate a simple Gemfile, placed in the current directory]" \
"gem[Create a simple gem, suitable for development with bundler]" \
+ "platform[Displays platform compatibility information]" \
"clean[Cleans up unused gems in your bundler directory]" \
"help[Describe available tasks or one specific task]"
ret=0
@@ -39,11 +41,13 @@ case $state in
'check' \
'list' \
'show' \
+ 'outdated' \
'console' \
'open' \
'viz' \
'init' \
'gem' \
+ 'platform' \
'help' && ret=0
;;
install)
@@ -71,6 +75,15 @@ case $state in
'(--verbose)--verbose[Enable verbose output mode]'
ret=0
;;
+ outdated)
+ _arguments \
+ '(--pre)--pre[Check for newer pre-release gems]' \
+ '(--source)--source[Check against a specific source]' \
+ '(--local)--local[Do not attempt to fetch gems remotely and use the gem cache instead]' \
+ '(--no-color)--no-color[Disable colorization in output]' \
+ '(--verbose)--verbose[Enable verbose output mode]'
+ ret=0
+ ;;
(open|show)
_gems=( $(bundle show 2> /dev/null | sed -e '/^ \*/!d; s/^ \* \([^ ]*\) .*/\1/') )
if [[ $_gems != "" ]]; then
diff --git a/plugins/bundler/bundler.plugin.zsh b/plugins/bundler/bundler.plugin.zsh
index c01241409..ba3d3f623 100644
--- a/plugins/bundler/bundler.plugin.zsh
+++ b/plugins/bundler/bundler.plugin.zsh
@@ -1,32 +1,98 @@
alias be="bundle exec"
-alias bi="bundle install"
alias bl="bundle list"
alias bp="bundle package"
alias bo="bundle open"
alias bu="bundle update"
+alias bi="bundle_install"
-# The following is based on https://github.com/gma/bundler-exec
+bundled_commands=(
+ annotate
+ cap
+ capify
+ cucumber
+ foodcritic
+ guard
+ irb
+ jekyll
+ kitchen
+ knife
+ middleman
+ nanoc
+ pry
+ puma
+ rackup
+ rainbows
+ rake
+ rspec
+ shotgun
+ sidekiq
+ spec
+ spork
+ spring
+ strainer
+ tailor
+ taps
+ thin
+ thor
+ unicorn
+ unicorn_rails
+)
-bundled_commands=(annotate berks cap capify cucumber foodcritic foreman guard jekyll kitchen knife middleman nanoc rackup rainbows rake rspec ruby shotgun spec spin spork strainer tailor thin thor unicorn unicorn_rails puma)
+# Remove $UNBUNDLED_COMMANDS from the bundled_commands list
+for cmd in $UNBUNDLED_COMMANDS; do
+ bundled_commands=(${bundled_commands#$cmd});
+done
+
+# Add $BUNDLED_COMMANDS to the bundled_commands list
+for cmd in $BUNDLED_COMMANDS; do
+ bundled_commands+=($cmd);
+done
## Functions
+bundle_install() {
+ if _bundler-installed && _within-bundled-project; then
+ local bundler_version=`bundle version | cut -d' ' -f3`
+ if [[ $bundler_version > '1.4.0' || $bundler_version = '1.4.0' ]]; then
+ if [[ "$OSTYPE" = darwin* ]]
+ then
+ local cores_num="$(sysctl hw.ncpu | awk '{print $2}')"
+ else
+ local cores_num="$(nproc)"
+ fi
+ bundle install --jobs=$cores_num $@
+ else
+ bundle install $@
+ fi
+ else
+ echo "Can't 'bundle install' outside a bundled project"
+ fi
+}
+
_bundler-installed() {
which bundle > /dev/null 2>&1
}
_within-bundled-project() {
- local check_dir=$PWD
- while [ $check_dir != "/" ]; do
+ local check_dir="$PWD"
+ while [ "$check_dir" != "/" ]; do
[ -f "$check_dir/Gemfile" ] && return
check_dir="$(dirname $check_dir)"
done
false
}
+_binstubbed() {
+ [ -f "./bin/${1}" ]
+}
+
_run-with-bundler() {
if _bundler-installed && _within-bundled-project; then
- bundle exec $@
+ if _binstubbed $1; then
+ ./bin/$@
+ else
+ bundle exec $@
+ fi
else
$@
fi
@@ -39,6 +105,6 @@ for cmd in $bundled_commands; do
alias $cmd=bundled_$cmd
if which _$cmd > /dev/null 2>&1; then
- compdef _$cmd bundled_$cmd=$cmd
+ compdef _$cmd bundled_$cmd=$cmd
fi
done