chruby icon indicating copy to clipboard operation
chruby copied to clipboard

Is there a way to get chruby to automatically do something when switching?

Open ghost opened this issue 10 years ago • 7 comments
trafficstars

I have a ruby 1.8 install where I must set RUBYLIB manually before any ruby programs will work ... is it possible to have chruby do this automatically when switching to ruby 1.8? I don't see a way ... it would be nice to be able to take arbitrary actions when switching rubies ...

ghost avatar Aug 28 '15 14:08 ghost

You would have to write your own post-switching commands system.

postmodern avatar Aug 28 '15 21:08 postmodern

Or use one of the zillions that already exist... Here are some notes from a year ago when I needed to solve this. (I ended up writing a one-off script, eschew overengineering)

  • autoenv: Overrides cd, that won't go well.
  • direnv: Well that's an awful lot of Go code.
  • anyenv: No README, looks kinda loose on security.
  • dotenv: Ruby/Rails-specific, requires changing your source code.
  • chenv: A lot of code plus a git-style UI. It's a popular name: chenv, chenv, etc.
  • aam: Apparently it's now named tem.
  • tem: Must be solving a completely different problem?

bronson avatar Dec 25 '15 16:12 bronson

@bronson right, the real problem is Bash doesn't support something like preexec_functions. You have to either inject a command into PROMPT_COMMAND (only works in interactive mode) or use trap DEBUG (not inherited by sub-processes). So most of these Bash solutions clobber any previously inserted Bash "hooks".

postmodern avatar Dec 25 '15 22:12 postmodern

Would the idea proposed in #227 make this easier?

ilikepi avatar Jan 05 '16 05:01 ilikepi

@ilikepi providing a function would allow users to manually set the trap DEBUG command. Manually injection into trap DEBUG is still impossibly/difficult unless set -T is set.

postmodern avatar Jan 06 '16 01:01 postmodern

Right... so does that mean you agree with this proposal (in a general sense)? I'm happy to put together a PR for further discussion.

On Jan 5, 2016, at 20:33, Postmodern [email protected] wrote:

@ilikepi providing a function would allow users to manually set the trap DEBUG command. Manually injection into trap DEBUG is still impossibly/difficult unless set -T is set.

— Reply to this email directly or view it on GitHub.

ilikepi avatar Jan 06 '16 01:01 ilikepi

rbenv has plugins that enable you to do things when switching versions and other things. Would love to see that in chruby, too.

bitboxer avatar Sep 25 '16 07:09 bitboxer