I'm trying to use rbenv (with plugins) & bundler to bulletproof some of our rake tasks. However, the rbenv shimmed versions of commands (of e.g. bundle
) depend on first running this (often found in .bashrc
or its equal):
eval "$(rbenv init -)"
This expands to shell commands which makes rbenv and plugins work correctly in the shell. It also means that rake tasks that work correctly in an interactive bash shell on my machine, won't work generally, e.g. evoked from /bin/sh or on another machine.
What I'd like to do is invoke this once for a shell in rake, and then continue to use that shell to invoke other commands in rake. Is that possible?
If not, can I copy envariables & shell functions resulting from one shell to a subsequent shells, in series?
Or am I left with either something like
eval "$(rbenv init -)" && other_command
or
rbenv exec bundle exec other_command
(The latter of which seemed to have its own problems).
I'm also open to "you're doing it wrong" strategic resets, modulo dodging rvm vs. rbenv jihads.
Update:
In answer to @konsolebox's question below, a ruby function I might want to use in my rake file might look something like this:
def rbenv_sh(command)
%x(eval "$(rbenv init -)" && #{command})
end
That would insure that command
would run in the correct rbenv context, without depending on dot-initialization files. I'm just looking for something better than that.