<commit_before>#!/bin/bash

set -e

{ # this ensures the entire script is downloaded #

tnvm_has() {
  type "$1" > /dev/null 2>&1
}

if [ -z "$TNVM_DIR" ]; then
  TNVM_DIR="$HOME/.tnvm"
fi

#
# Outputs the location to NVM depending on:
# * The availability of $NVM_SOURCE
# * The method used ("script" or "git" in the script, defaults to "git")
#
tnvm_source() {
  local NVM_METHOD
  NVM_METHOD="$1"
  local NVM_SOURCE_URL
  NVM_SOURCE_URL="$NVM_SOURCE"
  if [ -z "$NVM_SOURCE_URL" ]; then
    if [ "_$NVM_METHOD" = "_script" ]; then
      NVM_SOURCE_URL="https://raw.githubusercontent.com/ali-sdk/tnvm/master/tnvm.sh"
    elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
      NVM_SOURCE_URL="https://github.com/ali-sdk/tnvm.git"
    else
      echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
      return 1
    fi
  fi
  echo "$NVM_SOURCE_URL"
}

tnvm_download() {
  if tnvm_has "curl"; then
    curl -q $*
  elif tnvm_has "wget"; then
    # Emulate curl with wget
    ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
                           -e 's/-L //' \
                           -e 's/-I /--server-response /' \
                           -e 's/-s /-q /' \
                           -e 's/-o /-O /' \
                           -e 's/-C - /-c /')
    wget $ARGS
  fi
}

install_tnvm_from_git() {
  if [ -d "$TNVM_DIR/.git" ]; then
    echo "=> tnvm is already installed in $TNVM_DIR, trying to update using git"
    printf "\r=> "
    cd "$TNVM_DIR" && (command git pull 2> /dev/null || {
      echo >&2 "Failed to update tnvm, run 'git pull' in $TNVM_DIR yourself." && exit 1
    })
  else
    # Cloning to $TNVM_DIR
    echo "=> Downloading tnvm from git to '$TNVM_DIR'"<commit_msg>Download 优先使用 wget<commit_after>#!/bin/bash

set -e

{ # this ensures the entire script is downloaded #

tnvm_has() {
  type "$1" > /dev/null 2>&1
}

if [ -z "$TNVM_DIR" ]; then
  TNVM_DIR="$HOME/.tnvm"
fi

#
# Outputs the location to NVM depending on:
# * The availability of $NVM_SOURCE
# * The method used ("script" or "git" in the script, defaults to "git")
#
tnvm_source() {
  local NVM_METHOD
  NVM_METHOD="$1"
  local NVM_SOURCE_URL
  NVM_SOURCE_URL="$NVM_SOURCE"
  if [ -z "$NVM_SOURCE_URL" ]; then
    if [ "_$NVM_METHOD" = "_script" ]; then
      NVM_SOURCE_URL="https://raw.githubusercontent.com/ali-sdk/tnvm/master/tnvm.sh"
    elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
      NVM_SOURCE_URL="https://github.com/ali-sdk/tnvm.git"
    else
      echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
      return 1
    fi
  fi
  echo "$NVM_SOURCE_URL"
}

tnvm_download() {
  if tnvm_has "wget"; then
    # Emulate curl with wget
    ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
                           -e 's/-L //' \
                           -e 's/-I /--server-response /' \
                           -e 's/-s /-q /' \
                           -e 's/-o /-O /' \
                           -e 's/-C - /-c /')
    wget $ARGS
  elif tnvm_has "curl"; then
    curl -q $*
  fi
}

install_tnvm_from_git() {
  if [ -d "$TNVM_DIR/.git" ]; then
    echo "=> tnvm is already installed in $TNVM_DIR, trying to update using git"
    printf "\r=> "
    cd "$TNVM_DIR" && (command git pull 2> /dev/null || {
      echo >&2 "Failed to update tnvm, run 'git pull' in $TNVM_DIR yourself." && exit 1
    })
  else
    # Cloning to $TNVM_DIR
    echo "=> Downloading tnvm from git to '$TNVM_DIR'"
{'fraction_non_alphanumeric': 0.1589934229339434, 'fraction_numerical': 0.005147269087789534, 'mean_word_length': 2.0765171503957784, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6734120', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1313, 'n_words': 341}