scripts/utility in rvm-0.0.62 vs scripts/utility in rvm-0.0.63

- old
+ new

@@ -1,8 +1,8 @@ #!/bin/bash -function __rvm_info { +__rvm_info() { full_version=$(ruby -v) cat <<Info system: uname: "$(uname -a)" @@ -111,15 +111,15 @@ unset log_file command } function __rvm_cleanup_variables { __rvm_unset_ruby_variables - unset rvm_ruby_selected_flag rvm_action rvm_irbrc_file rvm_src_path rvm_path rvm_prefix_path rvm_gem_path rvm_command rvm_error_message rvm_gem_set_name rvm_url rvm_config_path rvm_bin_path rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_load_flag rvm_dump_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_head_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_log_path rvm_file_name + unset rvm_ruby_selected_flag rvm_action rvm_irbrc_file rvm_src_path rvm_path rvm_prefix_path rvm_gem_path rvm_command rvm_error_message rvm_gem_set_name rvm_url rvm_config_path rvm_bin_path rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_load_flag rvm_dump_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_log_path rvm_file_name } function __rvm_unset_ruby_variables { - unset rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_configure rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_ruby_binary rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string rvm_ruby_string rvm_ruby_src_path rvm_ruby_repo_url rvm_major_version rvm_minor_version rvm_ruby_gem_home + unset rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_configure rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_ruby_binary rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string rvm_ruby_string rvm_ruby_src_path rvm_ruby_repo_url rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_head_flag } # TODO: root user loadng of /etc/rvmrc function __rvm_load_rvmrc { if [[ -s ~/.rvmrc ]] ; then source ~/.rvmrc ; fi @@ -340,11 +340,11 @@ __rvm_log "fail" "Unknown ruby selected :(" result=1 fi } -function __rvm_db { +__rvm_db() { rvm_hash_file="$rvm_config_path/db" touch $rvm_hash_file key="$1" ; shift if [[ -z "$key" ]] ; then @@ -365,16 +365,17 @@ fi fi fi } -function __rvm_list { +__rvm_list() { if [[ ! -z "$rvm_all_flag" ]] ; then svn list http://svn.ruby-lang.org/repos/ruby/tags/ | grep 'v1_[8|9]' | sed 's#^v1_##' | sed 's#/$##' | awk -F'_' '{print "1."$1"."$2 " -l "$3}' | sed 's#p$##' echo -e "jruby 1.2.0\njruby 1.3.0\njruby (1.3.1, the default)\njruby 1.4.1\njruby --head" echo -e "rbx head (rubinius head, the default)\nrbx head --jit" echo -e "ree 1.8.6 --head\nree (1.8.7, the default)" + echo -e "mput head (shyouhei head, the default)" else current_ruby="$(which ruby | xargs dirname | xargs dirname | xargs basename 2> /dev/null)" echo -e "\nruby:\n" for version in $(/bin/ls -l $rvm_path/ 2> /dev/null | awk '/ ruby-[1-2].*/ { print $NF }') ; do string=$($rvm_path/$version/bin/ruby -v) @@ -406,10 +407,21 @@ else echo -e " $version : $string" fi done ; unset version + echo -e "\nmput:\n" + for version in $(/bin/ls $rvm_path/ 2> /dev/null | awk '/mput-.*/ { print $NF }') ; do + string="$($rvm_path/$version/bin/ruby -v | tr "\n" ' ' )" + if [[ "$version" = "$current_ruby" ]] ; then + echo -e "=> $version : $string" + selected="1" + else + echo -e " $version : $string" + fi + done ; unset version + if [[ -f "$rvm_path/default" ]] && [[ -s $rvm_path/default ]] ; then version=$(grep '^MY_RUBY_HOME' ~/.rvm/default | awk -F"'" '{print $2}' | xargs basename) if [[ ! -z "$version" ]] ; then echo -e "\ndefault:\n" string=$($rvm_path/$version/bin/ruby -v) @@ -463,10 +475,11 @@ rvm_temp_path="${rvm_temp_path:-"$rvm_path/tmp"}" rvm_ruby_repo_url="${rvm_ruby_repo_url:-"http://svn.ruby-lang.org/repos/ruby"}" # Rubinius sha1's will be available after RC1. rvm_rubinius_repo_url="${rvm_rubinius_repo_url:-"git://github.com/evanphx/rubinius.git"}" + rvm_shyouhei_repo_url="${rvm_shyouhei_repo_url:-"git://github.com/shyouhei/ruby.git"}" rvm_jruby_repo_url="${rvm_jruby_repo_url:-"git://kenai.com/jruby~main"}" rvm_ruby_load_path="." rvm_ruby_require="" __rvm_clean_path @@ -476,34 +489,33 @@ fi mkdir -p $rvm_src_path $rvm_bin_path $rvm_archives_path $rvm_gem_path $rvm_temp_path } -function __rvm_update { +__rvm_update() { if [[ "head" = "$rvm_ruby_revision" ]] || [[ ! -z "$rvm_self_flag" ]] || [[ "update" = "$rvm_action" ]] || [[ ! -z "$rvm_update_flag" ]] ; then __rvm_version __rvm_update_rvm - __rvm_version fi - __rvm_reload if [[ ! -z "$rvm_bin_flag" ]] ; then __rvm_bin_scripts ; fi if [[ ! -z "$rvm_rubygems_flag" ]] ; then __rvm_rubygems_setup ; fi } -function __rvm_update_rvm { - mkdir -p $rvm_src_path +__rvm_update_rvm() { + mkdir -p "$rvm_src_path" + __rvm_pushpop "$rvm_src_path" if [[ "head" = "$rvm_ruby_revision" ]] ; then if [[ -d "$rvm_src_path/rvm/.git" ]] ; then cd $rvm_src_path/rvm/ && git pull origin master && ./scripts/install else cd $rvm_src_path && git clone git://github.com/wayneeseguin/rvm.git && cd rvm/ && ./install fi else # TODO: rvm_install_path: - GEM_HOME="${GEM_HOME:-$(gem env gemdir user)}" - gem install rvm --no-rdoc --no-ri -q && $GEM_HOME/bin/rvm-install && source ~/.rvm/scripts/rvm + gem install rvm --no-rdoc --no-ri -q rvm && $(gem env gemdir user)/bin/rvm-install && source ~/.rvm/scripts/rvm fi + __rvm_pushpop } __rvm_reboot() { __rvm_log "warn" "Do you wish to reset rvm? ('yes', or 'no')" read response @@ -538,14 +550,13 @@ __rvm_use binary="$(echo $rvm_action | sed 's#do$##')" if [[ -x "$rvm_ruby_home/bin/$binary" ]] ; then load_path="$rvm_ruby_home/bin:$rvm_ruby_load_path" if [[ "ruby" = "$binary" ]] ; then - if [[ -z "$(echo $rvm_ruby_args | awk '/\.rb$/')" ]] ; then - #if [[ $rvm_ruby_args =~ '\.rb$' ]] ; then + if match "$rvm_ruby_args" "\.rb$" ; then if [[ -z "$prefix" ]] ; then prefix="-S" ; fi - if [[ ! -z "$rvm_ruby_args" ]] && [[ ! "$rvm_ruby_args" =~ "$prefix" ]] ; then + if ! match "$rvm_ruby_args" "$prefix" ; then rvm_ruby_args="$prefix $rvm_ruby_args" fi fi rvm_command="$rvm_ruby_home/bin/$binary $rvm_ruby_require -I$load_path $rvm_ruby_args" else @@ -834,30 +845,55 @@ openssl_os="os/compiler darwin-i386-cc" fi fi CFLAGS="-isysroot /Developer/SDKs/$sdk $rvm_archflags" ; export CFLAGS LDFLAGS="-Wl,-syslibroot /Developer/SDKs/$sdk $rvm_archflags" ; export LDFLAGS + # CXXFLAGS="-mmacosx-version-min="$(sw_vers -productVersion | awk -F'.' '{print $1"."$2}')" -isysroot /Developer/SDKs/$sdk " ; export CXXFLAGS ARCHFLAGS="$rvm_archflags" ; export ARCHFLAGS fi } __rvm_monitor() { - if [[ -d "test/" ]] ; then - : - elif [[ -d "spec/" ]] ; then - : - fi + if [[ -d "test/" ]] ; then test_timestamp=$(timestamp "test/") ; fi + if [[ -d "spec/" ]] ; then spec_timestamp=$(timestamp "spec/") ; fi + while : ; do + changed_test_files=() ; changed_spec_files=() + + if [[ -d "test/" ]] ; then + test_files=($(/bin/ls test/**/*_test.rb)) + for file in "${test_files[@]}"; do + if [[ $(timestamp $file) -gt $timestamp ]] ; then + array_push $changed_test_files + fi + done + fi + + if [[ -d "spec/" ]] ; then + spec_files=($(/bin/ls spec/**/*_spec.rb)) + for file in "${spec_files[@]}"; do + if [[ $(timestamp $file) -gt $timestamp ]] ; then + array_push $changed_spec_files + fi + done + fi + if [[ $(array_length $changed_test_files) -gt 0 ]] ; then + testrb "${myarray[*]}" + fi + if [[ $(array_length $changed_spec_files) -gt 0 ]] ; then + spec "${myarray[*]}" + fi + done } # # Actual Utility functions. # timestamp() { if [[ "Darwin" = "$(uname)" ]] ; then - echo $(stat -c "%Y" $1) - else echo $(stat -f "%m" $1) + else + echo $(stat -c "%Y" $1) fi } # Usage: contains "a_string" "${an_array[@]}" contains() { @@ -866,7 +902,32 @@ list=("$@") for index in "${!list[@]}" ; do [[ ${list[index]} = $pattern ]] && { echo $index ; return 0 ; } done echo -1 ; return 1 +} + +array_length() { + array=$1 ; return "${#array[*]}" +} + +array_push() { + array=$1 ; shift ; item=$2 + # TODO: allow loop over more arguments. + eval "index=\$((\${#${array}[*]} + $__array_start))" + eval "${array}[${index}]=${item}" +} + +match() { + if [[ ! -z "$BASH_VERSION" ]] && [[ ${BASH_VERSION:0:1} -gt 2 ]] && [[ ${BASH_VERSION:2:1} -ge 1 ]] ; then + [[ "$1" =~ $2 ]] ; return $? + # elif [[ ! -z "$ZSH_VERSION"]] && [[ ${ZSH_VERSION:0:1} -gt 3 ]] && [[ ${ZSH_VERSION:2:1} -ge 2 ]] && [[ ${ZSH_VERSION:4:1} -ge 4 ]] ; then + # return [[ "$1" =~ "$2" ]] + else + if [ ! -z "$(echo "$1" | awk "/${2}/")" ] ; then + return 0 + else + return 1 + fi + fi }