postmodern/chruby — pull request #250 by ArtemPyanykh (2014-02-07 21:10:31+00:00)
Title: Fix chruby-exec sourcing chruby.sh

chruby-exec works as follows:
1. source chruby.sh
2. check arguments
3. execute 'chruby {target_ruby} && $command' in a subshell

The problem is that sourced functions unlike environmental variables
are not 'inherited' by subshells.
(It is true at least in Ubuntu 12.04 LTS, where I tested this)

With "basic setup" you copy chruby.sh to /etc/profile.d, and this
chruby.sh sources /usr/share/local/chruby/chruby.sh
Then, when you invoke chruby_exec it works just fine, because
/usr/share/local/chruby/chruby.sh is sourced automaticaly by bash
through /etc/profile initialization script (which sources
/etc/profile.d/chruby.sh)

It would be great if you consider moving the process of sourcing
/usr/share/local/chruby/chruby.sh from the top of `chruby_exec` to a
command executed by a subshell. It would allow to use `chruby_exec`
without needing to source /usr/local/chruby/chruby.sh with shell init
scripts (/etc/profile.d/chruby.sh)

About function inheritance in a subshells

You could check it with the following setup:

- file set_func.sh:
====================
function test_func()
{
0
}
====================

- file get_func.sh:
===================
source ./set_func.sh

type test_func | head -1

exec "$SHELL" -i -l -c "type test_func | head -1"
==================

and then:
$ ./get_func.sh
test_func is a function
bash: type: test_func: not found