list 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #!/usr/bin/env bash
  2. rvm_base_except="selector"
  3. source "$rvm_scripts_path/base"
  4. source "$rvm_scripts_path/functions/list"
  5. __rvm_list_remote()
  6. {
  7. \typeset version
  8. rubies=($(
  9. __list_remote_all |
  10. __rvm_sed -e 's/.tar.*$//' -e 's/jruby-bin-/jruby-/' |
  11. __rvm_awk -F/ '{print $NF}' |
  12. \command \sort -u
  13. ))
  14. if
  15. (( ${#rubies[@]} == 0 ))
  16. then
  17. rvm_error "
  18. # No remote rubies available
  19. # Check 'rvm list known' for what can be installed.
  20. "
  21. return 1
  22. fi
  23. printf "%b" "\n# Remote rubies available:\n\n"
  24. for version in "${rubies[@]}"
  25. do
  26. if [[ -r "$rvm_rubies_path/$version/bin/ruby" ]]
  27. then rvm_log " * $version"
  28. else rvm_log " $version"
  29. fi
  30. done
  31. rvm_log "\n<comment># * - installed already</comment>\n"
  32. rvm_log "<comment># To download and install:</comment> <code>rvm install {name} --binary</code>\n\n"
  33. }
  34. __rvm_list_detect_arch()
  35. {
  36. if
  37. [[ -d "$rvm_gems_path/${__version}" && ! -d "$rvm_rubies_path/${__version%%@*}" ]]
  38. then
  39. __arch="ruby not installed"
  40. elif
  41. [[ ! -x "$rvm_rubies_path/${__version%%@*}/bin/ruby" ]]
  42. then
  43. __arch="missing bin/ruby"
  44. elif
  45. [[ -f "$rvm_rubies_path/${__version%%@*}/config" ]]
  46. then
  47. __arch="$(
  48. __rvm_awk -F= "\$1==\"target_cpu\" {gsub(/[\"']/,\"\"); print \$2}" < \
  49. $rvm_rubies_path/${__version%%@*}/config
  50. )" #'
  51. else
  52. __arch="$( __rvm_ruby_config_get "target_cpu" "$rvm_rubies_path/${__version%%@*}/bin/ruby" )"
  53. fi
  54. if
  55. [[ -z "${__arch}" ]]
  56. then
  57. case "${__version}" in
  58. (maglev-*|macruby-*) __arch="x86_64" ;;
  59. (mruby|mruby-*) __arch="x86_64" ;;
  60. (*) __arch="broken" ;;
  61. esac
  62. fi
  63. }
  64. __rvm_list_show_version_with_arch()
  65. {
  66. \typeset __arch __prefix __version __suffix
  67. __prefix="$1"
  68. __version="$2"
  69. __suffix="${3:-}"
  70. __rvm_list_detect_arch
  71. if rvm_pretty_print stdout
  72. then __version="${rvm_notify_clr:-}${__version}${rvm_reset_clr:-}"
  73. fi
  74. printf "%b" "${__prefix}${__version} [ ${__arch} ]${__suffix}"
  75. }
  76. __rvm_list_gemsets()
  77. {
  78. \typeset all_rubies version versions ruby_version_name current_ruby selected system_ruby system_version string binary prefix
  79. if [[ "${1:-""}" == "strings" ]]
  80. then
  81. __rvm_list_gemset_strings
  82. return 0
  83. fi
  84. current_ruby="$(__rvm_env_string)"
  85. all_rubies="$(__rvm_list_strings | sort)"
  86. printf "%b" "\nrvm gemsets\n"
  87. versions=($(
  88. __rvm_cd "${rvm_gems_path:-"$rvm_path/gems"}/"
  89. __rvm_find . -maxdepth 1 -mindepth 1 -print 2> /dev/null |
  90. __rvm_awk '/[a-z]*-.*/ {print $NF}' | sort
  91. ))
  92. for version in "${versions[@]//.\/}"
  93. do
  94. ruby_version_name="$(echo "$version" | __rvm_awk -F"${rvm_gemset_separator:-"@"}" '{print $1}')"
  95. if [[ "$all_rubies" != *"$ruby_version_name"* ]]
  96. then continue
  97. fi
  98. if [[ "$version" == "$current_ruby" ]]
  99. then prefix="=> "
  100. else prefix=" "
  101. fi
  102. __rvm_list_show_version_with_arch "\n${prefix}" "$version"
  103. done
  104. if [[ -f "$rvm_path/config/default" && -s "$rvm_path/config/default" ]]
  105. then
  106. version=$(
  107. __rvm_grep 'MY_RUBY_HOME' "$rvm_path/config/default" |
  108. \command \head -1 | __rvm_awk -F"'" '{print $2}' | __rvm_xargs basename --
  109. )
  110. if
  111. [[ -n "$version" ]]
  112. then
  113. printf "%b" "\nDefault Ruby (for new shells)\n"
  114. __rvm_list_show_version_with_arch "\n " "$version" "\n"
  115. fi
  116. fi
  117. printf "%b" "\n\n"
  118. return 0
  119. }
  120. __rvm_list_default()
  121. {
  122. \typeset version string
  123. if
  124. [[ "$1" == "string" ]]
  125. then
  126. "$rvm_scripts_path/alias" show default 2>/dev/null |
  127. __rvm_awk -F"${rvm_gemset_separator:-"@"}" '{print $1}' |
  128. __rvm_xargs basename --
  129. else
  130. if
  131. [[ -L "$rvm_rubies_path/default" ]]
  132. then
  133. version=$(
  134. "$rvm_scripts_path/alias" show default 2>/dev/null |
  135. __rvm_awk -F"${rvm_gemset_separator:-"@"}" '{print $1}' |
  136. __rvm_xargs basename --
  137. )
  138. if
  139. [[ -n "$version" ]]
  140. then
  141. printf "%b" "\nDefault Ruby (for new shells)\n"
  142. __rvm_list_show_version_with_arch "\n " "$version" "\n"
  143. fi
  144. fi
  145. fi
  146. printf "%b" "\n"
  147. return 0
  148. }
  149. __rvm_list_ruby_svn_tags()
  150. {
  151. \typeset -a tags
  152. \typeset prefix tag
  153. __rvm_read_lines tags <(
  154. svn list http://svn.ruby-lang.org/repos/ruby/tags/ | __rvm_awk '/^v1_[8|9]/{print}'
  155. )
  156. for tag in "${tags[@]}"
  157. do
  158. prefix="$(
  159. echo ${tag/\//} |
  160. __rvm_sed 's#^v1_##' |
  161. __rvm_awk -F'_' '{print "(ruby-)1."$1"."$2}' |
  162. __rvm_sed 's#p$##'
  163. )"
  164. echo "${prefix}-t${tag/\//}"
  165. done
  166. return 0
  167. }
  168. __rvm_list_known()
  169. {
  170. if [[ "${1:-""}" == "strings" ]]
  171. then
  172. __rvm_list_known_strings
  173. return 0
  174. fi
  175. if [[ -t 0 ]]
  176. then
  177. __rvm_pager_or_cat_v "$rvm_path/config/known"
  178. else
  179. \command \cat "$rvm_path/config/known"
  180. fi
  181. return $?
  182. }
  183. __rvm_list_rubies()
  184. {
  185. \typeset current_ruby rubies version selected system_ruby system_version \
  186. default_ruby string binary prefix
  187. if [[ "${1:-""}" == "strings" ]]
  188. then
  189. __rvm_list_strings
  190. return 0
  191. fi
  192. current_ruby="$( __rvm_env_string )"
  193. current_ruby="${current_ruby%${rvm_gemset_separator:-"@"}*}"
  194. default_ruby="$( "$rvm_scripts_path/alias" show default 2>/dev/null )"
  195. default_ruby="${default_ruby%${rvm_gemset_separator:-"@"}*}"
  196. rubies=($(
  197. __rvm_cd "$rvm_rubies_path/"
  198. __rvm_find . -maxdepth 1 -mindepth 1 -type d 2> /dev/null | sort
  199. ))
  200. for version in "${rubies[@]//.\/}"
  201. do
  202. if
  203. [[ "$version" == "$current_ruby" && "$version" == "$default_ruby" ]]
  204. then
  205. prefix="=* "
  206. elif
  207. [[ "$version" == "$current_ruby" ]]
  208. then
  209. prefix="=> "
  210. elif
  211. [[ "$version" == "$default_ruby" ]]
  212. then
  213. prefix=" * "
  214. else
  215. prefix=" "
  216. fi
  217. __rvm_list_show_version_with_arch "${prefix}" "$version" "\n"
  218. done
  219. if (( ${#rubies[@]} == 0 ))
  220. then
  221. printf "%b" "
  222. # No rvm rubies installed yet. Try 'rvm help install'.
  223. "
  224. else
  225. if [[ -z "${default_ruby}" ]]
  226. then
  227. printf "%b" "
  228. # Default ruby not set. Try 'rvm alias create default <ruby>'.
  229. "
  230. fi
  231. printf "%b" "
  232. # => - current
  233. # =* - current && default
  234. # * - default
  235. "
  236. fi
  237. printf "%b" "\n"
  238. return 0
  239. }
  240. # List all rvm installed rubies, default ruby and system ruby.
  241. # Display the rubies, indicate their architecture and indicate which is currently used.
  242. # This is not meant to be used with scripting. This is for interactive mode usage only.
  243. __rvm_list()
  244. {
  245. \typeset action="${1:-rubies}"
  246. shift
  247. case "${action}" in
  248. -r|--remote|remote)
  249. __rvm_list_remote "$@"
  250. ;;
  251. known|known_strings|gemsets|default|rubies|strings|ruby_svn_tags)
  252. __rvm_list_${action} "$@"
  253. ;;
  254. help)
  255. rvm_help list "${action}" "$@"
  256. ;;
  257. *)
  258. rvm_error_help "Unknown action '$action' for 'rvm list'." list "${action}" "$@"
  259. return 1
  260. ;;
  261. esac
  262. }
  263. __rvm_list "$@"