RVM after_cd Hook
I'm trying to use the RVM hooks to run a command after I cd
into a directory with my rails app.
The contents of my ~/.rvm/hooks/after_cd
is:
echo "Now using $rvm_ruby_string"
The contents of my ~/.rvm/hooks/after_use
is:
echo "Now using $rvm_ruby_string"
When I do $rmv use 1.9.2
I see my echo, but when I cd
into the rails root directory for my app I don't get any echo.
Am I using the after_cd
hook wrong?
$rvm -v
says:
rvm 1.0.8 by Wayne 开发者_如何学CE. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]
First you need to understand how rvm overwrite your system's default cd command.
Here's the answer explains this well.
In short, rvm defines a function like this in .rvm/script/cd
cd(){
builtin cd $* #run system cd
source after_cd_hooks #run hook scripts
}
And you can find this line if you look into how this cd() defined.
__rvm_project_rvmrc && __rvm_after_cd || true
__rvm_project_rvmrc
is the function to check if .rvmrc exists in the directory you change into.
So the hook scripts will only be sourced when .rvmrc exists in your project root.
So create your .rvmrc and try the cd again. Good Luck!
> /path/to/app/root/.rvmrc
cd /path/to/app/root
My rvm version:
rvm -v
rvm 1.23.14 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
精彩评论