@@ -63,62 +63,47 @@ if [ -d "$versions_dir" ]; then
6363 versions_dir=" $( realpath " $versions_dir " ) "
6464fi
6565
66+ list_versions () {
67+ shopt -s nullglob
68+ for path in " $versions_dir " /* ; do
69+ if [ -d " $path " ]; then
70+ if [ -n " $skip_aliases " ] && [ -L " $path " ]; then
71+ target=" $( realpath " $path " ) "
72+ [ " ${target%/* } " != " $versions_dir " ] || continue
73+ fi
74+ echo " ${path##*/ } "
75+ fi
76+ done
77+ shopt -u nullglob
78+ }
79+
6680if [ -n " $bare " ]; then
67- hit_prefix=" "
68- miss_prefix=" "
69- current_version=" "
70- include_system=" "
71- else
72- hit_prefix=" * "
73- miss_prefix=" "
74- current_version=" $( rbenv-version-name || true) "
75- include_system=" 1"
81+ list_versions
82+ exit 0
7683fi
7784
78- num_versions=0
79-
80- print_version () {
81- if [ " $1 " == " $current_version " ]; then
82- echo " ${hit_prefix} $( rbenv-version 2> /dev/null) "
83- else
84- echo " ${miss_prefix} $1 "
85- fi
86- num_versions=$(( num_versions + 1 ))
87- }
88-
8985sort_versions () {
9086 sed ' h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | \
9187 LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk ' {print $2}'
9288}
9389
94- # Include "system" in the non-bare output, if it exists
95- if [ -n " $include_system " ] && RBENV_VERSION=system rbenv-which ruby > /dev/null 2>&1 ; then
96- print_version system
97- fi
98-
99- shopt -s nullglob
100-
101- versions=($(
102- for path in " $versions_dir " /* ; do
103- if [ -d " $path " ]; then
104- if [ -n " $skip_aliases " ] && [ -L " $path " ]; then
105- target=" $( realpath " $path " ) "
106- [ " ${target%/* } " != " $versions_dir " ] || continue
107- fi
108- echo " ${path##*/ } "
90+ versions=" $(
91+ if RBENV_VERSION=system rbenv-which ruby > /dev/null 2>&1 ; then
92+ echo system
10993 fi
110- done
111- ) )
112-
113- sorted_versions=($( printf " %s\n" ${versions[@]} | sort_versions) )
114-
115- for version in ${sorted_versions[@]} ; do
116- print_version $version
117- done
118-
119- shopt -u nullglob
94+ list_versions | sort_versions
95+ ) "
12096
121- if [ " $num_versions " -eq 0 ] && [ -n " $include_system " ]; then
97+ if [ -z " $versions " ]; then
12298 echo " Warning: no Ruby detected on the system" >&2
12399 exit 1
124100fi
101+
102+ current_version=" $( rbenv-version-name || true) "
103+ while read -r version; do
104+ if [ " $version " == " $current_version " ]; then
105+ echo " * $( rbenv-version 2> /dev/null) "
106+ else
107+ echo " $version "
108+ fi
109+ done <<< " $versions"
0 commit comments