开发者

Why does it take a long time to change directories after installing RVM

I just installed RVM and it seems the cd command is taking an extra couple of seconds, why is this happening? Is there any wa开发者_JAVA技巧y to fix this?


This has been resolved in 0.1.39 and later versions of RVM. The behavior now only sources the .rvmrc file when you enter a projects directory tree for the first time. Subsequent cd's within that directory tree do not source the .rvmrc file. If you find yourself constantly jumping into and out of your projects directory tree, I would recommend using multiple terminals :)

One side benefit of this is you can now put more time-consuming actions, such as ensuring all your gems in your gemset are up to date, in .rvmrc to keep your project current without costing you time each time you cd.

To get the latest version of rvm, run: rvm update --head

Once that is installed, all new shells will have the improved behaviour -- for existing shells that you don't want to close, you can run 'rvm reload' to provide the new behaviour.

Cheers, -Dennis


This happens because it sources a file that intercepts the cd operation.

prompt:$ cat ~/.rvm/scripts/cd
#!/usr/bin/env bash

# Source a .rvmrc file in a directory after changing to it, if it exists.
 cd() {
   builtin cd "$@"
   if [[ "$rvm_project_rvmrc" != 0 ]] ; then
     local cwd ; cwd=$(pwd)
     while : ; do
       if [[ -z "$cwd" ]] || [[ "$HOME" = "$cwd" ]] || [[ "/" = "$cwd" ]] ; then
         if [[ "$rvm_project_rvmrc_default" != 0 ]] ; then
           rvm default 1>/dev/null 2>&1
         fi
         break
       else
         if [[ -f "$cwd/.rvmrc" ]] ; then
           source "$cwd/.rvmrc"
           break
         else
           cwd=$(dirname "$cwd")
         fi
       fi
     done
   fi
 }

This file checks for a .rvmrc file in the directory you are changing to, and set up an environment. That way you can have dir A run under ruby 1.8 and dir B run under ruby 1.9.

If you are happy to do away with this convenience you can comment out this file and be done with slow directory switching.

Alternatively you could contribute a patch that performs some caching so this is fast.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜