scripts/list in rvm-1.0.5 vs scripts/list in rvm-1.0.6
- old
+ new
@@ -1,205 +1,307 @@
#!/usr/bin/env bash
rvm_pretty_print=${rvm_pretty_print:-0}
rvm_base_except="selector"
+
source "$rvm_scripts_path/base"
+usage() {
+ printf "
+ Usage:
+
+ rvm list [action]
+
+ Actions:
+
+ {help,known,gemsets,default [string],rubies,strings,known_strings}
+
+"
+ return 0
+}
+
list_gemsets() {
+ local all_rubies version versions ruby_version_name current_ruby selected system_ruby system_version string binary
+
if [[ "${1:-""}" = "strings" ]]; then
list_gemset_strings
return 0
fi
- echo
current_ruby="$(__rvm_environment_identifier)"
- local all_rubies="$(list_strings)"
- printf "rvm gemsets\n"
- for version in $(ls "$rvm_gems_path/" 2> /dev/null | awk '/[a-z]*-.*/ {print $NF}') ; do
+ all_rubies="$(list_strings)"
+
+ printf "\nrvm gemsets\n"
+
+ versions=($(builtin cd "$rvm_gems_path/" ; find * -type d -maxdepth 0 -print 2> /dev/null | awk '/[a-z]*-.*/ {print $NF}'))
+ for version in "${versions[@]}" ; do
+
ruby_version_name="$(echo "$version" | awk -F"$rvm_gemset_separator" '{print $1}')"
[[ "$all_rubies" != *"$ruby_version_name"* ]] && continue
if echo "$version" | grep -q '^jruby-' ; then
string="[ $("$rvm_rubies_path/$ruby_version_name/bin/ruby" -v | awk '{print $NF}' | sed -e 's/\[//' -e 's/\]//') ]"
+
elif [[ -n "$(echo "$version" | awk '/^maglev-|^macruby-/')" ]] ; then
string="[ x86_64 ]"
+
else
string="[ $(file "$rvm_rubies_path/$ruby_version_name/bin/ruby" | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
- fi ; unset ruby_version_name
+ fi
+
printf "\n"
+
if [[ "$version" = "$current_ruby" ]]; then
printf "=> "
else
printf " "
fi
- if [[ $rvm_pretty_print -eq 1 ]] ; then
+
+ if [[ ${rvm_pretty_print:-0} -eq 1 ]] ; then
+
printf "$(tput setaf 2)$version$(tput sgr0) $string"
else
printf "$version $string"
fi
- done ; unset version
- if [[ -f "$rvm_config_path/default" ]] && [[ -s "$rvm_config_path/default" ]] ; then
+ done
+
+ if [[ -f "$rvm_config_path/default" && -s "$rvm_config_path/default" ]] ; then
+
version=$(grep 'MY_RUBY_HOME' "$rvm_config_path/default" | head -n1 | awk -F"'" '{print $2}' | xargs basename --)
- if [[ ! -z "$version" ]] ; then
+
+ if [[ -n "$version" ]] ; then
+
printf "\n\nDefault Ruby (for new shells)\n"
+
string="[ $(file "$rvm_rubies_path/$version/bin/ruby" | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
- if [[ $rvm_pretty_print -eq 1 ]] ; then
+
+ if [[ ${rvm_pretty_print:-0} -eq 1 ]] ; then
+
printf "\n $(tput setaf 2)$version$(tput sgr0) $string"
else
printf "\n $version $string"
fi
- fi ; unset version
- fi ; unset current_ruby version selected system_ruby system_version string binary
+
+ fi
+
+ fi
+
printf "\n\n"
+
+ return 0
}
list_default() {
+
+ local version string
+
if [[ "${args[0]:-""}" = "string" ]] ; then
+
"$rvm_scripts_path/alias" show default 2>/dev/null | awk -F"$rvm_gemset_separator" '{print $1}' | xargs basename --
else
if [[ -L "$rvm_rubies_path/default" ]]; then
version=$("$rvm_scripts_path/alias" show default 2>/dev/null | awk -F"$rvm_gemset_separator" '{print $1}' | xargs basename --)
- if [[ ! -z "$version" ]] ; then
+ if [[ -n "$version" ]] ; then
+
printf "\n\nDefault Ruby (for new shells)\n"
string="[ $(file "$rvm_rubies_path/$version/bin/ruby" | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | \tr "\n" ' ')]"
- if [[ $rvm_pretty_print -eq 1 ]] ; then
+ if [[ ${rvm_pretty_print:-0} -eq 1 ]] ; then
+
printf "\n $(tput setaf 2)$version$(tput sgr0) $string\n"
else
printf "\n $version $string\n"
fi
fi ; unset version
fi
fi
+
+ return 0
}
list_ruby_svn_tags() {
+ local prefix tag
+
while read -r tag
do
prefix="$(echo ${tag/\//} | sed 's#^v1_##' | awk -F'_' '{print "(ruby-)1."$1"."$2}' | sed 's#p$##')"
+
echo "${prefix}-t${tag/\//}"
- unset prefix tag
+
done < <(svn list http://svn.ruby-lang.org/repos/ruby/tags/ | awk '/^v1_[8|9]/')
+
+ return 0
}
# Query for valid rvm ruby strings
# This is meant to be used with scripting.
list_strings() {
- ls "$rvm_rubies_path"
+ (
+ cd "$rvm_rubies_path"
+
+ find * -type d -maxdepth 0
+ )
+
+ return $?
}
# This is meant to be used with scripting.
list_gemset_strings() {
- local all_rubies="$(list_strings)"
- for gemset in $(ls "$rvm_gems_path/" 2>/dev/null | xargs -n1 basename -- | \grep -v '^\(@\|doc$\|cache$\|system$\)' | sort); do
- local ruby_name="$(echo "$gemset" | awk -F$rvm_gemset_separator '{print $1}')"
+ local all_rubies ruby_name gemset gemsets
+
+ all_rubies="$(list_strings)"
+
+ gemsets=($(builtin cd "$rvm_gems_path" ; find * -type d -maxdepth 0 2>/dev/null | xargs -n1 basename -- | \grep -v '^\(@\|doc$\|cache$\|system$\)' | sort))
+
+ for gemset in "${gemsets[@]}" ; do
+
+ ruby_name="${gemset//${rvm_gemset_separator}*}"
+
[[ "$all_rubies" != *"$ruby_name"* ]] && continue
+
echo "$gemset"
done
+
+ return 0
}
# This is meant to be used with scripting.
list_known_strings() {
+
sed -e 's/#.*$//g' -e 's/(//g' -e 's/)//g' < "$rvm_config_path/known" | sort -r | uniq
+
+ return $?
}
list_known() {
+
if [[ "${1:-""}" = "strings" ]]; then
+
list_known_strings
+
return 0
fi
- if [[ "$rvm_interactive_flag" != "1" ]] ; then
+ if [[ ${rvm_interactive_flag:-0} -eq 0 ]] ; then
+
cat "$rvm_config_path/known"
+
else
- ${PAGER:-less} "$rvm_config_path/known"
+
+ less "$rvm_config_path/known"
+
fi
+
+ return $?
}
list_rubies_strings() {
- find "$rvm_rubies_path/" -type d -maxdepth 1 | tail -n+2 | xargs -n1 basename -- | __rvm_strip
+ ( builtin cd "$rvm_rubies_path" ; find -type d -maxdepth 0 | tail -n+2 | xargs -n1 basename -- | __rvm_strip )
+ return $?
}
list_rubies() {
+
+ local current_ruby rubies version selected system_ruby system_version string binary
+
if [[ "${1:-""}" = "strings" ]]; then list_rubies_strings ; return 0 ; fi
current_ruby="$(__rvm_environment_identifier | awk -F"$rvm_gemset_separator" '{print $1}')"
printf "\nrvm rubies\n"
- for version in $(ls "$rvm_rubies_path/" 2> /dev/null | awk '/[a-z]*-.*/ {print $NF}') ; do
+
+ rubies=($(builtin cd "$rvm_rubies_path/" ; find * -type d -maxdepth 0 2> /dev/null | awk '/[a-z]*-.*/ {print $NF}'))
+
+ for version in "${rubies[@]}" ; do
+
+ [[ ! -x "$rvm_rubies_path/$version/bin/ruby" ]] && continue
+
+ (
if echo "$version" | grep -q '^jruby-' ; then
+
string="[ $("$rvm_rubies_path/$version/bin/ruby" -v | awk '{print $NF}' | sed -e 's/\[//' -e 's/\]//') ]"
+
elif [[ ! -z "$(echo "$version" | awk '/^maglev-|^macruby-/')" ]] ; then
+
string="[ x86_64 ]"
+
else
+
string="[ $(file "$rvm_rubies_path/$version/bin/ruby" | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
fi
+
printf "\n"
+
if [[ "$version" = "$current_ruby" ]]; then
printf "=> "
else
printf " "
fi
+
# TODO: Only use tput for interactive terminal sessions.
- if [[ $rvm_pretty_print -eq 1 ]] ; then
+ if [[ ${rvm_pretty_print:-0} -eq 1 ]] ; then
+
printf "$(tput setaf 2)$version$(tput sgr0) $string"
else
printf "$version $string"
fi
- done ; unset version
+ )&
+ done ; wait
+
if [[ -f "$rvm_config_path/default" ]] && [[ -s "$rvm_config_path/default" ]] ; then
+
version=$(grep 'MY_RUBY_HOME' "$rvm_config_path/default" | head -n 1 | awk -F"'" '{print $2}' | xargs basename --)
- if [[ ! -z "$version" ]] ; then
+
+ if [[ -n "$version" ]] ; then
+
printf "\n\nDefault Ruby (for new shells)\n"
+
string="[ $(file "$rvm_rubies_path/$version/bin/ruby" | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | \tr "\n" ' ')]"
- if [[ $rvm_pretty_print -eq 1 ]] ; then
+
+ if [[ ${rvm_pretty_print:-0} -eq 1 ]] ; then
+
printf "\n $(tput setaf 2)$version$(tput sgr0) $string"
else
printf "\n $version $string"
fi
- fi ; unset version
- fi ; unset current_ruby version selected system_ruby system_version string binary
+
+ fi
+
+ fi
+
printf "\n\n"
+
+ return 0
}
# List all rvm installed rubies, default ruby and system ruby.
# Display the rubies, indicate their architecture and indicate which is currently used.
# This is not meant to be used with scripting. This is for interactive mode usage only.
args=($*)
action="${args[0]:-""}"
args=${args[@]:1} # Strip trailing / leading / extra spacing.
-if [[ "known" = "$action" ]] ; then
- list_known
-elif [[ "known_strings" = "$action" ]] ; then
- list_known_strings
-elif [[ "gemsets" = "$action" ]] ; then
- list_gemsets "$@"
-elif [[ "default" = "$action" ]] ; then
- list_default
-elif [[ -z "$action" ]] || [[ "rubies" = "$action" ]] ; then
- list_rubies "$@"
-elif [[ "strings" = "$action" ]] ; then
- list_strings
-elif [[ "ruby_svn_tags" = "$action" ]] ; then
- list_ruby_svn_tags
-else # help
- printf "
- Usage:
+if [[ -z "$action" ]] ; then list_rubies ; exit 0 ; fi
- rvm list {known,gemsets,default [string],rubies,strings,known_strings}
-
-"
- false
-fi
+case "$action" in
+ known) list_known ;;
+ known_strings) list_known_strings ;;
+ gemsets) list_gemsets "$@" ;;
+ default) list_default ;;
+ rubies) list_rubies "$@" ;;
+ strings) list_strings ;;
+ ruby_svn_tags) list_ruby_svn_tags ;;
+ help) usage ;;
+ *) usage ; exit 1 ;;
+esac
exit $?