dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

bundler.plugin.zsh (1942B)


      1 bundled_commands=(
      2   annotate
      3   cap
      4   capify
      5   cucumber
      6   foodcritic
      7   guard
      8   hanami
      9   irb
     10   jekyll
     11   kitchen
     12   knife
     13   middleman
     14   nanoc
     15   pry
     16   puma
     17   rackup
     18   rainbows
     19   rake
     20   rspec
     21   rubocop
     22   shotgun
     23   sidekiq
     24   spec
     25   spork
     26   spring
     27   strainer
     28   tailor
     29   taps
     30   thin
     31   thor
     32   unicorn
     33   unicorn_rails
     34 )
     35 
     36 # Remove $UNBUNDLED_COMMANDS from the bundled_commands list
     37 for cmd in $UNBUNDLED_COMMANDS; do
     38   bundled_commands=(${bundled_commands#$cmd});
     39 done
     40 
     41 # Add $BUNDLED_COMMANDS to the bundled_commands list
     42 for cmd in $BUNDLED_COMMANDS; do
     43   bundled_commands+=($cmd);
     44 done
     45 
     46 ## Functions
     47 
     48 bundle_install() {
     49   if ! _bundler-installed; then
     50     echo "Bundler is not installed"
     51   elif ! _within-bundled-project; then
     52     echo "Can't 'bundle install' outside a bundled project"
     53   else
     54     local bundler_version=`bundle version | cut -d' ' -f3`
     55     if [[ $bundler_version > '1.4.0' || $bundler_version = '1.4.0' ]]; then
     56       if [[ "$OSTYPE" = (darwin|freebsd)* ]]
     57       then
     58         local cores_num="$(sysctl -n hw.ncpu)"
     59       else
     60         local cores_num="$(nproc)"
     61       fi
     62       bundle install --jobs=$cores_num $@
     63     else
     64       bundle install $@
     65     fi
     66   fi
     67 }
     68 
     69 _bundler-installed() {
     70   which bundle > /dev/null 2>&1
     71 }
     72 
     73 _within-bundled-project() {
     74   local check_dir="$PWD"
     75   while [ "$check_dir" != "/" ]; do
     76     [ -f "$check_dir/Gemfile" -o -f "$check_dir/gems.rb" ] && return
     77     check_dir="$(dirname $check_dir)"
     78   done
     79   false
     80 }
     81 
     82 _binstubbed() {
     83   [ -f "./bin/${1}" ]
     84 }
     85 
     86 _run-with-bundler() {
     87   if _bundler-installed && _within-bundled-project; then
     88     if _binstubbed $1; then
     89       ./bin/${^^@}
     90     else
     91       bundle exec $@
     92     fi
     93   else
     94     $@
     95   fi
     96 }
     97 
     98 ## Main program
     99 for cmd in $bundled_commands; do
    100   eval "function unbundled_$cmd () { $cmd \$@ }"
    101   eval "function bundled_$cmd () { _run-with-bundler $cmd \$@}"
    102   alias $cmd=bundled_$cmd
    103 
    104   if which _$cmd > /dev/null 2>&1; then
    105     compdef _$cmd bundled_$cmd=$cmd
    106   fi
    107 done