Fish and RVM

Decided to move from bash/zsh/etc to fish shell? Developing in ruby? So, you probably use rvm.

If you are lucky, you found this step-by-step tutorial that integrates rvm with fish. After using fish for a while, you noticed that your cd function is missing some features… WTF!?

Why would the cd function lose features if “RVM just manipulates environment variables”? Rvm is not just manipulating environment variables, it also overrides shell commands like cd.

set -l GITHUB
➜ curl --create-dirs -o ~/.config/fish/functions/ $GITHUB/
➜ curl -o ~/.config/fish/functions/ $GITHUB/

As you can see, the third step from the tutorial is actually redefining the cd function.

Fish has a philosophy different than most of the shells: “Many other shells have a large library of builtin commands. Most of these commands are also available as standalone commands, but have been implemented in the shell anyway for whatever reason. To avoid code duplication, and to avoid the confusion of subtly differing versions of the same command, fish only implements builtins for actions which cannot be performed by a regular command.”

While you have the builtin command cd you also have the regular command defined in fish. The latter adds more features to the cd function.

Functions in fish are lazy loaded, and ones priority depends on the directory that it was defined. When following the step-by-step guide, the cd function is copied to a user specific directory which has a higher priority than the default fish functions directory. Thus, the regular cd command is never loaded.

One of the features your cd command loses is being able to cd into your previous path:

cd -
cd: The directory '-' does not exist

Currently, fish has no support for replacing functions without losing its functionality, and as I was using rvm at that time I decided to create such behaviour. This functionality was added to Oh My Fish and its rvm plugin already fixes this issue.

  1. Date: July 29, 2012
  2. Tags: fish, oh my fish, and rvm
comments powered by Disqus