chruby
chruby copied to clipboard
.ruby-version support for chruby-exec
Hi,
Have you thought about adding support for reading the ruby version from .ruby-version to chruby-exec?
Thanks,
Ian
What would the use case be? cd /project; command
should be enough to trigger auto-loading?
The use case is whatever the use case for chruby-exec is, but without the need to specify the version manually.
i.e some people like @regularfry don't use the functions in chruby.sh, they use chruby-exec to load a shell with the ruby environment defined, as detailed: [http://www.blackkettle.org/blog/2013/08/13/how-i-ruby-part-1-development/](in his blog post).
This would mean rather than:
chruby-exec 1.9.3-p429 -- bash
you could do:
chruby-exec -- bash
...and it would automatically detect the version from .ruby-version the same way auto.sh does.
My other use case would be for scripts/cron jobs etc running gem binaries - I want to be able to do: chruby-exec -- commandhere and have it automatically pick the right ruby version from .ruby-version, rather than having to specify it, which means when I change ruby versions on a project, i've got to remember all the places i've hardcoded the version - like init scripts, cron jobs etc.
Thanks,
Ian
Why can't you do cd /project && $SHELL
or bash -l -c 'cd /project && ./bin/foo'
?
To put this into perspective, this is all that chruby-exec
does under the hood: https://github.com/postmodern/chruby/blob/master/bin/chruby-exec#L36-L40 Perhaps we could add a chruby-auto-exec
command, but I think it's possibly only using the auto.sh
hooks that run before each command.
I could, but it would just be good to be able to do: "cd /project && chruby-exec -- cmd" without having to have chruby +auto loaded in the profile and worrying about whether it had loaded in that instance.
A chruby-auto-exec would be cool.
It could obviously use/share the .ruby-version parsing code from auto.sh so should be quite simple?
+1 it'd be great to have something like rvm in <path> do <command>
That would be great!
@tamird how would that be different from cd path && command
?
@postmodern it would be the same, but would not require a "special" shell where chruby/auto.sh
has been sourced.
Yeah, it would be much neater for doing scripts, startup config, cron jobs etc - you just tell chruby you want to execute this command it would sort loading the right ruby version.
Even better, would be the ability to read a .env file and also setup some config environments, but I suspect that might be further than you want to go.
For starting cron jobs, you really should specify which SHELL you want to run the command under, and have everything preconfigured. Otherwise, you become depending on an rvm-like command for the environment.
What do you mean by have everything preconfigured? - have an example?
If you want your cron job to run in an ideal shell environment, run $SHELL -l -c "..."
with any additional configuration at the top of the cron file or in the shell's dot-files.
True, chruby-exec
hides the $SHELL -l -c '...'
part, but it still requires you set SHELL
and have your shell configured as desired.
Yep, agree with this for env's. but it would still be much neater for chruby-exec to pick the ruby version up from .ruby-version
What about users who do not want auto-switching ever enabled?
They wouldn't enable it? - you were talking above of having a separate command - chruby-auto-exec ?
To avoid adding yet another command, I was thinking of adding a --auto
option. There needs to be a way for users to explicitly specify they want to use .ruby-version
.
That sounds great. Thanks @postmodern !
I'm still on the fence about this feature, as it seems we're shoe horning additional functionality into chruby-exec
. Perhaps we should add a chruby-shell
, to run commands with chruby pre-loaded.
Er, turn chruby-exec
into something like chruby-shell
.
chruby-exec --auto -- "cd /srv/my_app && ruby command here"
@postmodern seems like a nice, general solution to the "I need this behavior for this command" problem.
@tamird better description would be when you need to use chruby, but can't modify the shell's configuration to load chruby.sh
and auto.sh
.
sure :)
Does there need to be .ruby-version support at the chruby level at all? Seems like something a wrapper should be handling.
@regularfry what do you mean by wrapper?
@regularfry I guess that's why it's implemented separately in auto.sh - if you don't want that functionality, you don't have to load it and it's not slowing plain chruby (or chruby-exec as you use) down by checking it...
@postmodern --auto sounds good!
has there been any progress here?
I know it's been about 7 years, but this feature request would still be useful. 8)