on rvm’s *cd* script

I’ve seen a lot of misinformation and missing facts in the discussion about rvm's cd script, which overrides the shell’s cd and allows it to pass through, so I’m posting this to clear the air a bit.

  • Only one of a dozen or so posts I’ve read about raising concern with it cited a concrete problem with it. It was also for an earlier version of rvm, and it may already be fixed. The poster was very civil about it, unlike many of the people who complained about it but didn’t provide an example.
  • Most people, even those who write shell scripts with logic, don’t do anything advanced with cd. In fact, there aren’t many advanced uses of cd. I would check for existence of a directory rather than use the return code even if I knew about cd's return values and didn't expect anything to override it. It's more explicit.
  • It’s easy to only load rvm on demand. Just alias it to something short.
  • cd is not being replaced by a program, it’s being replaced by a shell function. There is very little overhead, unless an .rvmrc file is found, in which case it does something quite useful.
  • Many, many people have used rvm without even noticing that it overrides cd. I knew about .rvmrc's behavior, but I thought that the shell must have provided a hook for the directory changing!
  • The shim approach has the downside of having to run a command to update the shims. Though that could probably be fixed by having the command automatically run after gem install.
  • rvm’s approach to cd is a lot like rack middleware, even in how it calls to a function. Do you find rack useful, or would you rather have your requests and responses unadulterated when they get to your controller?
  • I trust Wayne Seguin’s shell-scripting chops.

Finally, one thing I’d like to know, is if rvm was loaded, would another script be able to override cd in the same way that rvm does, and would both script’s hooks be called?. I suspect that the answer is yes. Does anyone know? Please @ me on twitter if you do.

Finally, I’d like to close this post by saying thanks to Wayne, and that rvm has been a tremendous boost to the ruby community. It has helped get people ruby 1.9, JRuby, and rubinius. Projects in other languages, like nvm and n, have taken inspiration from it. In short, it’s a fantastic project!

Update: Josh Cheek pointed out that rvm provides an after_cd hook. Also in 1.7.0, project .rvmrc files are off by default, so the cd script is opt-in.

  1. izumiya reblogged this from batkin
  2. apps-developer reblogged this from batkin
  3. search-engine-marketing-philippi reblogged this from batkin
  4. seo-victoria reblogged this from batkin
  5. jonbaer reblogged this from batkin
  6. batkin posted this
Short URL for this post: http://tmblr.co/ZrpDay8FOPqk