Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4327808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:35:25+00:00 2026-05-21T09:35:25+00:00

One thing that RVM can do is notice when you’ve changed directories, look for

  • 0

One thing that RVM can do is notice when you’ve changed directories, look for an .rvmrc, and change your current Ruby version and gemset according to that file’s contents. It makes this change as soon as you change into that directory and outputs a message accordingly.

How does it detect a change in the current working directory? I can imagine an extremely crude way of doing this: run a daemon that runs as the current user and keeps checking the results of pwd. But I’m sure that’s not what it does.

Another approach might be to alias cd to change directories but also check for an .rvmrc and change gemsets if so instructed.

Is there a Unix system hook for changing directories, or is there some other trick that RVM is using?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:35:26+00:00Added an answer on May 21, 2026 at 9:35 am

    How does [RVM] detect a change in the current working directory?

    This entirely depends on the shell and even shell version. The simplest method for accomplishing this is, as was suggested, overriding cd by defining a function of the same name. Be sure to call the built in cd function or you will cause either very nasty or very amusing side effects (depending on perspective).

    cd() {
      builtin cd $*
      echo "Changed directories from '${OLDPWD}' to '${PWD}'."
    }
    

    By placing this in a text source file and sourcing the file you can load this custom cd functionality into the session sourcing the file.

    wayneeseguin$ cd /tmp
    Changed directories from '/home/wayneeseguin' to '/tmp'.
    

    If you would like this to always be in effect for interactive shells in your user account either place the function definition into ~/.bash_profile. Alternatively you can source the text file in which you stored the function in from ~/.bash_profile. You can read more about Bash startup files in the Bash manual.

    The Ruby enVironment Manager (RVM) is written in and targeted mainly for the Bash shell. RVM will work in the ZSH shell which allows you to add function calls to after a cd action. This is by far the best way to approach solving this task. So, if your shell allows for it, by all means use this method. RVM does.

    For an extensive example you can look at RVM’s cd functionality on GitHub.

    RVM utilizes this functionality for loading per-project (directory, really) .rvmrc files as well as providing users with the ability to configure various hooks. You can read more about RVM’s hooks on the documentation website.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm enjoying Ruby on Rails but one thing that seems overwhelming is the shear
There's one thing that I can't figure out. When I try to run rails
The one thing that can still get me is what to return from methods?
We just changed over to mercurial from subversion and there is one thing that
One thing that bothers me about nHibernate is that it is not 100% compile
One thing that really bothers me about Google Code is that fact that it
One thing that's bothered me with vi is that paste (p) inserts lines after
One thing that seems particularly easy to do in the Flash IDE but difficult
I am relatively new to Xcode and one thing that has bothered me is
I am new to using numpy and one thing that I really don't understand

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.