Skip to content

Commit c7fc125

Browse files
committed
Make RUBIES a colon-delimited string instead of an array
Motivation --- Fix chruby in Claude. Core issue is RUBIES is not set in claude shells. Before --- RUBIES was a bash array, and bash arrays cannot be exported. So every fresh subshell — including every Claude Code Bash tool call — started with an empty RUBIES and chruby failed to resolve any Ruby version, even though RUBY_ROOT, GEM_HOME, and PATH were already set correctly in that same subshell. After --- RUBIES is exported as a colon-delimited string, like PATH, so chruby resolves correctly in any subshell, including Claude's. One side effect: RUBIES now shows up in every child process's environment (e.g. in `env` output), which it never did as an array.
1 parent a543a35 commit c7fc125

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

share/chruby/chruby.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
CHRUBY_VERSION="0.3.9"
2-
RUBIES=()
2+
RUBIES=""
33

44
for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do
5-
[[ -d "$dir" && -n "$(command ls -A "$dir")" ]] && RUBIES+=("$dir"/*)
5+
if [[ -d "$dir" && -n "$(command ls -A "$dir")" ]]; then
6+
for ruby in "$dir"/*; do
7+
RUBIES="${RUBIES:+$RUBIES:}$ruby"
8+
done
9+
fi
610
done
7-
unset dir
11+
unset dir ruby
12+
export RUBIES
813

914
function chruby_reset()
1015
{
@@ -71,7 +76,8 @@ function chruby()
7176
;;
7277
"")
7378
local dir ruby
74-
for dir in "${RUBIES[@]}"; do
79+
local IFS=:
80+
for dir in $RUBIES; do
7581
dir="${dir%%/}"; ruby="${dir##*/}"
7682
if [[ "$dir" == "$RUBY_ROOT" ]]; then
7783
echo " * ${ruby} ${RUBYOPT}"
@@ -84,7 +90,8 @@ function chruby()
8490
system) chruby_reset ;;
8591
*)
8692
local dir ruby match
87-
for dir in "${RUBIES[@]}"; do
93+
local IFS=:
94+
for dir in $RUBIES; do
8895
dir="${dir%%/}"; ruby="${dir##*/}"
8996
case "$ruby" in
9097
"$1") match="$dir" && break ;;

0 commit comments

Comments
 (0)