From 031e96f9e3e728fcd60892fa4c25d5f5f29a6bf0 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 19 Nov 2025 05:58:31 +0000 Subject: [PATCH 1/2] Fix failing tests in czruby functions - czruby_set_default: Check for empty argument before applying default - czruby_reset: Properly remove old RUBY_ROOT/bin and GEM_HOME/bin from PATH when switching rubies, preventing PATH growth - czruby_purge: Use readlink on Linux instead of greadlink (macOS only), and directly set RUBIES_DEFAULT to system when purging default ruby --- fn/czruby_purge | 18 +++++++++++++----- fn/czruby_reset | 18 ++++++++++++++---- fn/czruby_set_default | 3 ++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/fn/czruby_purge b/fn/czruby_purge index 1b9a76b..45c7517 100644 --- a/fn/czruby_purge +++ b/fn/czruby_purge @@ -9,8 +9,12 @@ czruby_purge() { return 1 fi - # Store current default ruby - default_ruby="$(greadlink -f "$czruby_datadir/default" 2>/dev/null)" + # Store current default ruby (use readlink on Linux, greadlink on macOS) + if command -v greadlink &>/dev/null; then + default_ruby="$(greadlink -f "$czruby_datadir/default" 2>/dev/null)" + else + default_ruby="$(readlink -f "$czruby_datadir/default" 2>/dev/null)" + fi default_ruby="${default_ruby:t}" # Process each file in czruby_datadir @@ -44,10 +48,14 @@ czruby_purge() { rm "$file" ((purged++)) - # If this was the default, remove the default symlink + # If this was the default, reset to system if [[ "$key" == "$default_ruby" ]]; then - rm "$czruby_datadir/default" - czruby_set_default system + rm -f "$czruby_datadir/default" + RUBIES_DEFAULT="system" + # Create symlink to system config if it exists + if [[ -f "$czruby_datadir/system" ]]; then + ln -fs "$czruby_datadir/system" "$czruby_datadir/default" + fi fi fi done diff --git a/fn/czruby_reset b/fn/czruby_reset index 5c4b800..5b07321 100644 --- a/fn/czruby_reset +++ b/fn/czruby_reset @@ -6,13 +6,23 @@ local ruby_root="${2:-$RUBY_ROOT}" local excludes=() - # TODO consider replacing loop - for place in "$gem_path"; do + # Remove old RUBY_ROOT/bin from path + if [[ -n "$RUBY_ROOT" ]]; then + excludes+=("$RUBY_ROOT/bin") + fi + + # Remove old GEM_HOME/bin from path + if [[ -n "$GEM_HOME" ]]; then + excludes+=("$GEM_HOME/bin") + fi + + # Remove all gem_path bin directories from path + for place in $gem_path; do local bin="$place/bin" - excludes=("$bin" "${excludes[@]}") # Append to the array correctly + excludes+=("$bin") done - if [[ $#gem_path > 0 ]]; then + if [[ ${#excludes[@]} -gt 0 ]]; then # remove any excluded paths path=(${path:|excludes}) fi diff --git a/fn/czruby_set_default b/fn/czruby_set_default index 8256b91..79d6741 100644 --- a/fn/czruby_set_default +++ b/fn/czruby_set_default @@ -1,7 +1,8 @@ # Sets the default Ruby environment to use when no specific version is specified. { + # Check for empty argument before applying default + [[ -z "$1" ]] && return 1 local choice="${1:-system}" - [[ -z $choice ]] && return 1 if [[ -z ${(M)rubies:#*$choice} ]]; then print "That ruby is not available\n\n" czruby From 20b5d40527068c018f1c83a3e49a4f48644ea5ba Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 19 Nov 2025 06:27:05 +0000 Subject: [PATCH 2/2] Fix czruby_purge handling of empty datadir Use zsh (N) glob qualifier to handle empty directories without raising a "no matches found" error. --- fn/czruby_purge | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fn/czruby_purge b/fn/czruby_purge index 45c7517..fcba484 100644 --- a/fn/czruby_purge +++ b/fn/czruby_purge @@ -18,7 +18,8 @@ czruby_purge() { default_ruby="${default_ruby:t}" # Process each file in czruby_datadir - for file in "$czruby_datadir"/*; do + # Use (N) glob qualifier to handle empty directory without error + for file in "$czruby_datadir"/*(N); do [[ -f "$file" ]] || continue key="${file:t}"