You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support sourcing the Spin environment file from a Bash script
At Shopify we want to use TruffleRuby inside other Spin projects, so
it’s important that `source /path/to/truffleruby/.spin/bin/env` works
from those projects’ Bash scripts as well as directly from the command
line.
When the environment file is sourced by another script, `$0` is the name
of the main script being executed rather than the environment file
itself, so `dirname "$0"` will return the (probably incorrect) directory
containing the main script rather than `/path/to/truffleruby/.spin/bin`
as expected.
In Bash, `$BASH_SOURCE` is an array containing the source filenames of
all currently-executing shell functions [0], of which the first is
always the most recent [1], so we can use `$BASH_SOURCE[0]` to directly
ask for the filename of the environment file instead of assuming that
`$0` will contain it.
This change makes `source` work correctly at the cost of relying on a
Bash-specific feature. We also need to support zsh, so support for that
will be added in the next commit.
[0] https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fSOURCE
[1] https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-FUNCNAME
0 commit comments