postmodern / chruby

Changes the current Ruby
MIT License
2.85k stars 190 forks source link

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

Open ghost opened 8 years ago

ghost commented 8 years ago

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 ...

postmodern commented 8 years ago

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

bronson commented 8 years ago

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)

postmodern commented 8 years ago

@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".

ilikepi commented 8 years ago

Would the idea proposed in #227 make this easier?

postmodern commented 8 years ago

@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.

ilikepi commented 8 years ago

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 notifications@github.com 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.

bitboxer commented 7 years ago

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