rvmrc_set 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/usr/bin/env bash
  2. __rvm_set_versions_conf()
  3. {
  4. \typeset gemset identifier
  5. if [[ -s .versions.conf ]]
  6. then
  7. \command \mv .versions.conf .versions.conf.$(__rvm_date +%m.%d.%Y-%H:%M:%S)
  8. rvm_warn ".version.conf is not empty, moving aside to preserve."
  9. fi
  10. identifier=$(__rvm_env_string)
  11. gemset=${identifier#*@}
  12. identifier=${identifier%@*}
  13. printf "%b" "ruby=$identifier
  14. " >> .versions.conf
  15. if [[ -n "$gemset" && "$gemset" != "$identifier" ]]
  16. then
  17. printf "%b" "ruby-gemset=$gemset
  18. " >> .versions.conf
  19. else
  20. printf "%b" "#ruby-gemset=my-projectit
  21. " >> .versions.conf
  22. fi
  23. printf "%b" "#ruby-gem-install=bundler rake
  24. #ruby-bundle-install=true
  25. " >> .versions.conf
  26. }
  27. __rvm_set_ruby_version()
  28. {
  29. if
  30. [[ -s .ruby-version ]]
  31. then
  32. \command \mv .ruby-version .ruby-version.$(__rvm_date +%m.%d.%Y-%H:%M:%S)
  33. rvm_warn ".ruby-version is not empty, moving aside to preserve."
  34. fi
  35. \typeset __version="$(__rvm_env_string)"
  36. case "${__version}" in
  37. (*@*)
  38. if
  39. [[ -s .ruby-gemset ]]
  40. then
  41. \command \mv .ruby-gemset .ruby-gemset.$(__rvm_date +%m.%d.%Y-%H:%M:%S)
  42. rvm_warn ".ruby-gemset is not empty, moving aside to preserve."
  43. fi
  44. echo "${__version##*@}" > .ruby-gemset
  45. ;;
  46. (*)
  47. if
  48. [[ -s .ruby-gemset ]]
  49. then
  50. \command \mv .ruby-gemset .ruby-gemset.$(__rvm_date +%m.%d.%Y-%H:%M:%S)
  51. rvm_warn ".ruby-gemset not needed, moving aside to preserve."
  52. fi
  53. ;;
  54. esac
  55. echo "${__version%@*}" > .ruby-version
  56. }
  57. __rvm_set_rvmrc()
  58. {
  59. \typeset flags identifier short_identifier gem_file
  60. true ${rvm_verbose_flag:=0}
  61. if [[ "$HOME" != "$PWD" && "${rvm_prefix:-}" != "$PWD" ]]
  62. then
  63. if (( rvm_verbose_flag ))
  64. then flags="use "
  65. fi
  66. if [[ -s .rvmrc ]]
  67. then
  68. \command \mv .rvmrc .rvmrc.$(__rvm_date +%m.%d.%Y-%H:%M:%S)
  69. rvm_warn ".rvmrc is not empty, moving aside to preserve."
  70. fi
  71. identifier=$(__rvm_env_string)
  72. short_identifier="${identifier#ruby-}"
  73. short_identifier="${short_identifier%%-*}"
  74. printf "%b" "#!/usr/bin/env bash
  75. # This is an RVM Project .rvmrc file, used to automatically load the ruby
  76. # development environment upon cd'ing into the directory
  77. # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
  78. # Only full ruby name is supported here, for short names use:
  79. # echo \"rvm use ${short_identifier}\" > .rvmrc
  80. environment_id=\"$identifier\"
  81. # Uncomment the following lines if you want to verify rvm version per project
  82. # rvmrc_rvm_version=\"${rvm_version}\" # 1.10.1 seems like a safe start
  83. # eval \"\$(echo \${rvm_version}.\${rvmrc_rvm_version} | awk -F. '{print \"[[ \"\$1*65536+\$2*256+\$3\" -ge \"\$4*65536+\$5*256+\$6\" ]]\"}' )\" || {
  84. # echo \"This .rvmrc file requires at least RVM \${rvmrc_rvm_version}, aborting loading.\"
  85. # exit 1
  86. # }
  87. " >> .rvmrc
  88. if __rvm_string_match "$identifier" "jruby*"
  89. then
  90. printf "%b" "
  91. # Uncomment following line if you want options to be set only for given project.
  92. # PROJECT_JRUBY_OPTS=( --1.9 )
  93. # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
  94. # chmod +x \${rvm_path}/hooks/after_use_jruby_opts
  95. " >> .rvmrc
  96. fi
  97. printf "%b" "
  98. # First we attempt to load the desired environment directly from the environment
  99. # file. This is very fast and efficient compared to running through the entire
  100. # CLI and selector. If you want feedback on which environment was used then
  101. # insert the word 'use' after --create as this triggers verbose mode.
  102. if [[ -d \"\${rvm_path:-\$HOME/.rvm}/environments\"
  103. && -s \"\${rvm_path:-\$HOME/.rvm}/environments/\$environment_id\" ]]
  104. then
  105. \\. \"\${rvm_path:-\$HOME/.rvm}/environments/\$environment_id\"
  106. for __hook in \"\${rvm_path:-\$HOME/.rvm}/hooks/after_use\"*
  107. do
  108. if [[ -f \"\${__hook}\" && -x \"\${__hook}\" && -s \"\${__hook}\" ]]
  109. then \\. \"\${__hook}\" || true
  110. fi
  111. done
  112. unset __hook
  113. " >> .rvmrc
  114. if [[ " $flags " == *" use "* ]]
  115. then printf "%b" " if (( \${rvm_use_flag:=1} >= 1 )) # display automatically" >> .rvmrc
  116. else printf "%b" " if (( \${rvm_use_flag:=1} >= 2 )) # display only when forced" >> .rvmrc
  117. fi
  118. printf "%b" "
  119. then
  120. if [[ \$- == *i* ]] # check for interactive shells
  121. then printf \"%b\" \"Using: \$(tput setaf 2 2>/dev/null)\$GEM_HOME\$(tput sgr0 2>/dev/null)\\\\n\" # show the user the ruby and gemset they are using in green
  122. else printf \"%b\" \"Using: \$GEM_HOME\\\\n\" # don't use colors in non-interactive shells
  123. fi
  124. fi
  125. " >> .rvmrc
  126. printf "%b" "else
  127. # If the environment file has not yet been created, use the RVM CLI to select.
  128. rvm --create $flags \"\$environment_id\" || {
  129. echo \"Failed to create RVM environment '\${environment_id}'.\"
  130. return 1
  131. }
  132. fi
  133. " >> .rvmrc
  134. for gem_file in *.gems
  135. do
  136. case "$gem_file" in
  137. (\*.gems) continue ;;
  138. esac
  139. printf "%b" "
  140. # If you use an RVM gemset file to install a list of gems (*.gems), you can have
  141. # it be automatically loaded. Uncomment the following and adjust the filename if
  142. # necessary.
  143. #
  144. # filename=\".gems\"
  145. # if [[ -s \"\$filename\" ]]
  146. # then
  147. # rvm gemset import \"\$filename\" | GREP_OPTIONS=\"\" \\\\command \\grep -v already | GREP_OPTIONS=\"\" \command \grep -v listed | GREP_OPTIONS=\"\" \command \grep -v complete | \command \sed '/^$/d'
  148. # fi
  149. " >> .rvmrc
  150. done
  151. if [[ -s Gemfile ]]
  152. then
  153. printf "%b" "
  154. # If you use bundler, this might be useful to you:
  155. # if [[ -s Gemfile ]] && {
  156. # ! builtin command -v bundle >/dev/null ||
  157. # builtin command -v bundle | GREP_OPTIONS=\"\" \\\\command \\grep \$rvm_path/bin/bundle >/dev/null
  158. # }
  159. # then
  160. # printf \"%b\" \"The rubygem 'bundler' is not installed. Installing it now.\\\\n\"
  161. # gem install bundler
  162. # fi
  163. # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
  164. # then
  165. # bundle install | GREP_OPTIONS=\"\" \\\\command \\grep -vE '^Using|Your bundle is complete'
  166. # fi
  167. " >> .rvmrc
  168. fi
  169. else
  170. rvm_error ".rvmrc cannot be set in your home directory.\
  171. \nThe home .rvmrc is for global rvm settings only."
  172. fi
  173. }