Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions fn/czruby_purge
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ 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
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}"

Expand Down Expand Up @@ -44,10 +49,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
Expand Down
18 changes: 14 additions & 4 deletions fn/czruby_reset
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fn/czruby_set_default
Original file line number Diff line number Diff line change
@@ -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
Expand Down