Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add --cd-hack option. And, well, the corresponding cd hack. Sigh. See…

… what you have made me done?
  • Loading branch information...
commit 98b5a09aaa346be8c035d6ce6e23f627240458eb 1 parent a51599c
Hendrik Mans authored November 19, 2011

Showing 2 changed files with 34 additions and 2 deletions. Show diff stats Hide diff stats

  1. 10  README.md
  2. 26  init.sh
10  README.md
Source Rendered
@@ -13,7 +13,7 @@ See, rbfu does one thing and one thing only:
13 13
 
14 14
 rbfu (especially compared to RVM and rbenv) **does not do any of the following**:
15 15
 
16  
-* **Switch Ruby versions automagically.** You have to switch versions explicitly (eg. `rbfu 1.9.3-p0`). This is by design; please don't submit patches adding any kind of automatic behavior. I don't approve of automatic behavior. I would *hate* if one day rbfu grows sentient and enslaves all of mankind.
  16
+* **Switch Ruby versions automagically.** Out of the box, you have to switch versions explicitly (eg. `rbfu 1.9.3-p0`). If you really, _really_ want RVM-like behaviour, you can configure rbfu to automatically pick up `.rbfu-version` files, but this feature should be considered experimental. And unloved. Highly unloved.
17 17
 * **Install Rubies.** Well, there's a little helper command available that hooks into the excellent [ruby-build](https://github.com/sstephenson/ruby-build), but you can also compile your Rubies yourself if that is what pushes your buttons, you dirty old girl.
18 18
 * **Override existing shell functions or executables.** I've never been a big fan of RVM hooking into `cd`, but in my opinion rbenv's shim executable approach is even worse. rbfu completely and entirely stays in the background. Like a good roadie. Or a silent assassin. Except that it doesn't kill you.
19 19
 * **Manage gemsets.** Seriously, please just use [Bundler](http://gembundler.com/) for managing your gems, it's great.
@@ -28,6 +28,10 @@ Add the following line to your favorite startup script (eg. `.bash_profile`):
28 28
 
29 29
     [ -d "$HOME/.rbfu" ] && eval "$($HOME/.rbfu/init.sh)"
30 30
 
  31
+If you want rbfu to automatically switch Ruby versions after switching directories, like .rvm does it, you can supply the `--cd-hack` option. In this case, the above line would read:
  32
+
  33
+    [ -d "$HOME/.rbfu" ] && eval "$($HOME/.rbfu/init.sh --cd-hack)"
  34
+
31 35
 Don't forget to reload your shell environment or start a new shell session for the change to be picked up.
32 36
 
33 37
 Finally, install your favorite Ruby versions through `rbfu-install` (this requires
@@ -79,7 +83,9 @@ on the command line:
79 83
 
80 84
 Note that if a `$HOME/.rbfu-version` file is present, rbfu will initially activate the Ruby version mentioned therein when the environment is created (ie., from your shell startup script).
81 85
 
82  
-#### Setting a user-specific default
  86
+#### Switching Ruby versions automagically
  87
+
  88
+If you have the `--cd-hack` option enabled (see the Installation section for details), rbfu will look for these files whenever you switch to a new directory, and act upon them automatically. Please note that this functionality is experimental (and probably buggy/dangerous). It is generally recommended you switch Ruby versions manually; this functionality is merely provided for people who really, _really_ want rbfu to kind of work like RVM. _SEE, YOU MADE ME ADD THIS. I HOPE YOU ENJOY IT. SNARL, SNARL, GRUNT ETC._
83 89
 
84 90
 ### Uninstalling
85 91
 
26  init.sh
... ...
@@ -1,5 +1,17 @@
1 1
 #!/usr/bin/env bash
2 2
 
  3
+# parse options
  4
+#
  5
+for opt in $*; do
  6
+  case $opt in
  7
+    --cd-hack)
  8
+      RBFU_CD_HACK=1
  9
+      ;;
  10
+  esac
  11
+done    
  12
+
  13
+# configure rbfu
  14
+# 
3 15
 cat <<EOD
4 16
 function rbfu () {
5 17
   eval "\`rbfu-activate \$1\`"
@@ -8,3 +20,17 @@ function rbfu () {
8 20
 export PATH=~/.rbfu/bin:\$PATH
9 21
 [ -f $HOME/.rbfu-version ] && rbfu
10 22
 EOD
  23
+
  24
+# optional cd hack
  25
+#
  26
+if [ $RBFU_CD_HACK ]; then
  27
+  cat <<EOD
  28
+function cd() {
  29
+  if builtin cd "\$@"; then
  30
+    [ -f "\$PWD/.rbfu-version" ] && rbfu
  31
+  else
  32
+    return \$?
  33
+  fi
  34
+}
  35
+EOD
  36
+fi

0 notes on commit 98b5a09

Please sign in to comment.
Something went wrong with that request. Please try again.