<commit_before># Rust Version Manager
# ====================
#
# To use the rsvm command source this file from your bash profile.

RSVM_VERSION="0.1.0"

# Auto detect the NVM_DIR
if [ ! -d "$RSVM_DIR" ]
then
  export RSVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd)
fi

rsvm_append_path()
{
  local newpath
  if [[ ":$1:" != *":$2:"* ]];
  then
    newpath="${1:+"$1:"}$2"
  else
    newpath="$1"
  fi
  echo $newpath
}

export PATH=$(rsvm_append_path $PATH $RSVM_DIR/current/dist/bin)
export LD_LIBRARY_PATH=$(rsvm_append_path $LD_LIBRARY_PATH $RSVM_DIR/current/dist/lib)
export MANPATH=$(rsvm_append_path $MANPATH $RSVM_DIR/current/dist/share/man)

rsvm_use()
{
  if [ -e "$RSVM_DIR/$1" ]
  then
    echo -n "Activating rust $1 ... "

    rm -rf $RSVM_DIR/current
    ln -s $RSVM_DIR/$1 $RSVM_DIR/current
    source $RSVM_DIR/rsvm.sh

    echo "done"
  else
    echo "The specified version $1 of rust is not installed..."
    echo "You might want to install it with the following command:"
    echo ""
    echo "rsvm install $1"
  fi
}

rsvm_current()
{
  if [ ! -e $RSVM_DIR/current ]
  then
    echo "N/A"
    return
  fi
  target=`echo $(readlink $RSVM_DIR/current)|tr "/" "\n"`
  echo ${target[@]} | awk '{print$NF}'
}

rsvm_ls()
{
  local VERSION_PATTERN="(nightly|[0-9]\.[0-9]+(\.[0-9]+)?(-alpha)?)"
  local DIRECTORIES=$(find $RSVM_DIR -maxdepth 1 -mindepth 1 -type d -exec basename '{}' \; \
    | egrep ^$VERSION_PATTERN \
    | sort)

  echo "Installed versions:"
  echo ""

  if [ $(echo $DIRECTORIES | wc -l) = 0 ]
  then
    echo '  -  None';
  else
    for line in $(echo $DIRECTORIES | tr " " "\n")
    do
      if [ `rsvm_current` = "$line" ]
      then
        echo "  =>  $line"
      else
        echo "  -   $line"
      fi
    done
  fi
}

rsvm_init_folder_structure()
{
  echo -n "Creating the respective folders for rust $1 ... "

  mkdir -p "$RSVM_DIR/$1/src"
  mkdir -p "$RSVM_DIR/$1/dist"

  echo "done"
}

rsvm_install()
{
  local CURRENT_DIR=`pwd`
  local version


  if [[ $1 = "nightly" ]]
  then
    version=nightly.`date "+%Y%m%d%H%M%S"`
  else
    version=$1
  fi
  rsvm_init_folder_structure $version
  local SRC="$RSVM_DIR/$version/src"
  local DIST="$RSVM_DIR/$version/dist"

  cd $SRC

  local ARCH=`uname -m`
  local OSTYPE=`uname`
  local PLATFORM
  if [ "$OSTYPE" = "Linux" ]
  then
    PLATFORM=$ARCH-unknown-linux-gnu
  fi

  if [ -f "rust-$1-$PLATFORM.tar.gz" ]
  then
    echo "Sources for rust $version already downloaded ..."
  else
    echo -n "Downloading sources for rust $version ... "
    curl -o "rust-$1-$PLATFORM.tar.gz" "https://static.rust-lang.org/dist/rust-$1-$PLATFORM.tar.gz"
    echo "done"
  fi

  if [ -e "rust-$1" ]
  then
    echo "Sources for rust $version already extracted ..."
  else
    echo -n "Extracting source ... "
    tar -xzf "rust-$1-$PLATFORM.tar.gz"
    mv "rust-$1-$PLATFORM" "rust-$1"
    echo "done"
  fi

  if [ ! -f $SRC/rust-$1/bin/cargo ]
  then
    echo -n "Downloading sources for cargo nightly ... "
    curl -o "cargo-nightly-$PLATFORM.tar.gz" "https://static.rust-lang.org/cargo-dist/cargo-nightly-$PLATFORM.tar.gz"
    echo "done"

    echo -n "Extracting source ... "
    tar -xzf "cargo-nightly-$PLATFORM.tar.gz"
    mv "cargo-nightly-$PLATFORM" "cargo-nightly"
    echo "done"

    cd "$SRC/cargo-nightly"
    sh install.sh --prefix=$DIST
  fi

  cd "$SRC/rust-$1"
  sh install.sh --prefix=$DIST

  echo ""
  echo "And we are done. Have fun using rust $version."

  cd $CURRENT_DIR
}

rsvm_ls_remote()
{
  local VERSION_PATTERN="(nightly|[0-9]\.[0-9]+(\.[0-9]+)?(-alpha)?)"
  local ARCH=`uname -m`
  local OSTYPE=`uname`
  local VERSIONS
  local PLATFORM
  if [ "$OSTYPE" = "Linux" ]
  then
    PLATFORM=$ARCH-unknown-linux-gnu
    # TODO OTHER PLATFORM
  fi
  VERSIONS=$(curl -s http://static.rust-lang.org/dist/index.html -o - \
    | command egrep -o "rust-$VERSION_PATTERN-$PLATFORM.tar.gz" \
    | command uniq \
    | command egrep -o "$VERSION_PATTERN" \
    | command sort)
  for VERSION in $VERSIONS;
  do
    echo $VERSION
  done
}

rsvm_uninstall()
{
  if [ `rsvm_current` = "$1" ]
  then
    echo "rsvm: Cannot uninstall currently-active version, $1"
    return
  fi
  if [ ! -d "$RSVM_DIR/$1" ]
  then
    echo "$! version is not installed yet... "
    return
  fi
  echo "uninstall $1 ..."
  rm -rI "$RSVM_DIR/$1"
}

rsvm()<commit_msg>rsvm.sh: Support Mac OS X<commit_after># Rust Version Manager
# ====================
#
# To use the rsvm command source this file from your bash profile.

RSVM_VERSION="0.1.0"

# Auto detect the NVM_DIR
if [ ! -d "$RSVM_DIR" ]
then
  export RSVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd)
fi

rsvm_append_path()
{
  local newpath
  if [[ ":$1:" != *":$2:"* ]];
  then
    newpath="${1:+"$1:"}$2"
  else
    newpath="$1"
  fi
  echo $newpath
}

export PATH=$(rsvm_append_path $PATH $RSVM_DIR/current/dist/bin)
export LD_LIBRARY_PATH=$(rsvm_append_path $LD_LIBRARY_PATH $RSVM_DIR/current/dist/lib)
export MANPATH=$(rsvm_append_path $MANPATH $RSVM_DIR/current/dist/share/man)

rsvm_use()
{
  if [ -e "$RSVM_DIR/$1" ]
  then
    echo -n "Activating rust $1 ... "

    rm -rf $RSVM_DIR/current
    ln -s $RSVM_DIR/$1 $RSVM_DIR/current
    source $RSVM_DIR/rsvm.sh

    echo "done"
  else
    echo "The specified version $1 of rust is not installed..."
    echo "You might want to install it with the following command:"
    echo ""
    echo "rsvm install $1"
  fi
}

rsvm_current()
{
  if [ ! -e $RSVM_DIR/current ]
  then
    echo "N/A"
    return
  fi
  target=`echo $(readlink $RSVM_DIR/current)|tr "/" "\n"`
  echo ${target[@]} | awk '{print$NF}'
}

rsvm_ls()
{
  local VERSION_PATTERN="(nightly|[0-9]\.[0-9]+(\.[0-9]+)?(-alpha)?)"
  local DIRECTORIES=$(find $RSVM_DIR -maxdepth 1 -mindepth 1 -type d -exec basename '{}' \; \
    | egrep ^$VERSION_PATTERN \
    | sort)

  echo "Installed versions:"
  echo ""

  if [ $(echo $DIRECTORIES | wc -l) = 0 ]
  then
    echo '  -  None';
  else
    for line in $(echo $DIRECTORIES | tr " " "\n")
    do
      if [ `rsvm_current` = "$line" ]
      then
        echo "  =>  $line"
      else
        echo "  -   $line"
      fi
    done
  fi
}

rsvm_init_folder_structure()
{
  echo -n "Creating the respective folders for rust $1 ... "

  mkdir -p "$RSVM_DIR/$1/src"
  mkdir -p "$RSVM_DIR/$1/dist"

  echo "done"
}

rsvm_install()
{
  local CURRENT_DIR=`pwd`
  local version


  if [[ $1 = "nightly" ]]
  then
    version=nightly.`date "+%Y%m%d%H%M%S"`
  else
    version=$1
  fi
  rsvm_init_folder_structure $version
  local SRC="$RSVM_DIR/$version/src"
  local DIST="$RSVM_DIR/$version/dist"

  cd $SRC

  local ARCH=`uname -m`
  local OSTYPE=`uname -s`
  case $OSTYPE in
    Linux)
      PLATFORM=$ARCH-unknown-linux-gnu
      ;;
    Darwin)
      PLATFORM=$ARCH-apple-darwin
      ;;
    *)
      echo "rsvm: Not support this platform, $OSTYPE"
      return
      ;;
  esac

  if [ -f "rust-$1-$PLATFORM.tar.gz" ]
  then
    echo "Sources for rust $version already downloaded ..."
  else
    echo -n "Downloading sources for rust $version ... "
    curl -o "rust-$1-$PLATFORM.tar.gz" "https://static.rust-lang.org/dist/rust-$1-$PLATFORM.tar.gz"
    echo "done"
  fi

  if [ -e "rust-$1" ]
  then
    echo "Sources for rust $version already extracted ..."
  else
    echo -n "Extracting source ... "
    tar -xzf "rust-$1-$PLATFORM.tar.gz"
    mv "rust-$1-$PLATFORM" "rust-$1"
    echo "done"
  fi

  if [ ! -f $SRC/rust-$1/bin/cargo ]
  then
    echo -n "Downloading sources for cargo nightly ... "
    curl -o "cargo-nightly-$PLATFORM.tar.gz" "https://static.rust-lang.org/cargo-dist/cargo-nightly-$PLATFORM.tar.gz"
    echo "done"

    echo -n "Extracting source ... "
    tar -xzf "cargo-nightly-$PLATFORM.tar.gz"
    mv "cargo-nightly-$PLATFORM" "cargo-nightly"
    echo "done"

    cd "$SRC/cargo-nightly"
    sh install.sh --prefix=$DIST
  fi

  cd "$SRC/rust-$1"
  sh install.sh --prefix=$DIST

  echo ""
  echo "And we are done. Have fun using rust $version."

  cd $CURRENT_DIR
}

rsvm_ls_remote()
{
  local VERSION_PATTERN="(nightly|[0-9]\.[0-9]+(\.[0-9]+)?(-alpha)?)"
  local ARCH=`uname -m`
  local OSTYPE=`uname -s`
  local VERSIONS
  local PLATFORM
  case $OSTYPE in
    Linux)
      PLATFORM=$ARCH-unknown-linux-gnu
      ;;
    Darwin)
      PLATFORM=$ARCH-apple-darwin
      ;;
    *)
      echo "rsvm: Not support this platform, $OSTYPE"
      return
      ;;
  esac

  VERSIONS=$(curl -s http://static.rust-lang.org/dist/index.html -o - \
    | command egrep -o "rust-$VERSION_PATTERN-$PLATFORM.tar.gz" \
    | command uniq \
    | command egrep -o "$VERSION_PATTERN" \
    | command sort)
  for VERSION in $VERSIONS;
  do
    echo $VERSION
  done
}

rsvm_uninstall()
{
  if [ `rsvm_current` = "$1" ]
  then
    echo "rsvm: Cannot uninstall currently-active version, $1"
    return
  fi
  if [ ! -d "$RSVM_DIR/$1" ]
  then
    echo "$! version is not installed yet... "
    return
  fi
  echo "uninstall $1 ..."
  rm -rI "$RSVM_DIR/$1"
}

rsvm()
{'fraction_non_alphanumeric': 0.16622073578595317, 'fraction_numerical': 0.011148272017837236, 'mean_word_length': 2.6423061307348763, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2151948', 'n_tokens_mistral': 3606, 'n_tokens_neox': 3484, 'n_words': 838}