Skip to content
Closed
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: 17 additions & 4 deletions share/chruby/chruby.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
CHRUBY_VERSION="0.3.9"
RUBIES=()

for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do
[[ -d "$dir" && -n "$(ls -A "$dir")" ]] && RUBIES+=("$dir"/*)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to consider is the sort order. In zsh, you can get a proper numeric sort fairly easily, so 2.10 is greater than 2.9.

Here is a zsh one-liner.

echo "${(@n)RUBIES}"

Or to print each Ruby in order:

printf "%s\n" "${(@n)RUBIES:t}"

done
unset dir
function chruby_rubies()
{
if [ -n "$ZSH_VERSION" ]; then
setopt local_options nodotglob nullglob
else
trap "$(shopt -p dotglob nullglob)" RETURN
shopt -u dotglob
shopt -s nullglob
fi

local dir
for dir in "$@"; do
[[ -d "$dir" ]] && RUBIES+=("$dir"/*)
done
}
chruby_rubies "$PREFIX/opt/rubies" "$HOME/.rubies"
unset -f chruby_rubies

function chruby_reset()
{
Expand Down