<commit_before>#
# Rough attempt at parsing the sample profiling log
# file generated if ENVTOOLS_PROFILING_STARTUP wants
# set to true...
#
function parseProfilingLogs {
  while read tim ;do
    crt=$(echo $tim | awk -F'~~~' '{print $2}')
    cmd=$(echo $tim | awk -F'~~~' '{print $3}')
    diff=$((${crt}-10#0$last))
    printf "%s %s\n" "$diff" "$cmd"
    last=${crt}
  done < $HOME/sample-profiling.log
}

#
# Test if argument is a positive number
#
function isNumber {
  local re='^[0-9]+([.][0-9]+)?$'
  if ! [[ $1 =~ $re ]] ; then
    return 1
  else
    return 0
  fi
}

#
# Test for OS types
#
function isWindows {
  local LOCAL_OS=$OS
  if [ "$LOCAL_OS" == "" ]; then
    LOCAL_OS=$(uname)
  fi
  [[ "$LOCAL_OS" == "MINGW32_NT-6.1" || "$LOCAL_OS" == "MINGW64_NT-10.0" ]]
}
function isMac {
  local LOCAL_OS=$OS
  if [ "$LOCAL_OS" == "" ]; then
    LOCAL_OS=$(uname)
  fi
  [[ "$LOCAL_OS" == "Darwin" ]]
}
function isLinux {
  local LOCAL_OS=$OS
  if [ "$LOCAL_OS" == "" ]; then
    LOCAL_OS=$(uname)
  fi
  [[ "$LOCAL_OS" == "Linux" ]]
}

#
# returns 0 if the user confirmed yes, 1 otherwise
# $1 optional prompt, default to "Continue? "
# $2 optional default, "yes" or "no" - no default
#
function confirm () {
  local default=""
  local prompt="Continue?"

  if isValid "$1"; then
    prompt=$1
  fi

  case "$2" in
    [nN][oO]|[nN])
      default="no"
      prompt="$prompt [y|N] "
      ;;
    [yY][eE][sS]|[yY])
      default="yes"
      prompt="$prompt [Y|n] "
      ;;
    *)
      prompt="$prompt [y|n] "
      ;;
  esac

  while true; do
    txtBoldWhite "$prompt"
    read -n 1 resp
    case "$resp" in
      [nN])
        echo && return 1
        ;;
      [yY])
        echo && return 0
        ;;
      *)
        if [ "$default" == "no" ]; then
          return 1
        elif [ "$default" == "yes" ]; then
          return 0
        else
          txtRed "Yes or no?" "nl"
        fi
    esac
  done
}

#
# returns true if a variable is defined (set) and value's length > 0
# returns false otherwise
#
function isValid {
  ! [[ -z "$1" ]]
}

#
# returns true if the argument is an existing program
# returns false otherwise
#
function isInstalled {
  type "$1" >/dev/null 2>&1 || { return -1; }
}

#
# returns 0 if the global variable GLOBAL_CONTINUE is true or unset
# return 1 otherwise.
# If a parameter is passed, it is used instead of GLOBAL_CONTINUE
#
function shouldContinue {
  local flag=$GLOBAL_CONTINUE

  if isValid "$1"; then<commit_msg>Fixing bash return (-1 is not a valid error on some distro)<commit_after>#
# Rough attempt at parsing the sample profiling log
# file generated if ENVTOOLS_PROFILING_STARTUP wants
# set to true...
#
function parseProfilingLogs {
  while read tim ;do
    crt=$(echo $tim | awk -F'~~~' '{print $2}')
    cmd=$(echo $tim | awk -F'~~~' '{print $3}')
    diff=$((${crt}-10#0$last))
    printf "%s %s\n" "$diff" "$cmd"
    last=${crt}
  done < $HOME/sample-profiling.log
}

#
# Test if argument is a positive number
#
function isNumber {
  local re='^[0-9]+([.][0-9]+)?$'
  if ! [[ $1 =~ $re ]] ; then
    return 1
  else
    return 0
  fi
}

#
# Test for OS types
#
function isWindows {
  local LOCAL_OS=$OS
  if [ "$LOCAL_OS" == "" ]; then
    LOCAL_OS=$(uname)
  fi
  [[ "$LOCAL_OS" == "MINGW32_NT-6.1" || "$LOCAL_OS" == "MINGW64_NT-10.0" ]]
}
function isMac {
  local LOCAL_OS=$OS
  if [ "$LOCAL_OS" == "" ]; then
    LOCAL_OS=$(uname)
  fi
  [[ "$LOCAL_OS" == "Darwin" ]]
}
function isLinux {
  local LOCAL_OS=$OS
  if [ "$LOCAL_OS" == "" ]; then
    LOCAL_OS=$(uname)
  fi
  [[ "$LOCAL_OS" == "Linux" ]]
}

#
# returns 0 if the user confirmed yes, 1 otherwise
# $1 optional prompt, default to "Continue? "
# $2 optional default, "yes" or "no" - no default
#
function confirm () {
  local default=""
  local prompt="Continue?"

  if isValid "$1"; then
    prompt=$1
  fi

  case "$2" in
    [nN][oO]|[nN])
      default="no"
      prompt="$prompt [y|N] "
      ;;
    [yY][eE][sS]|[yY])
      default="yes"
      prompt="$prompt [Y|n] "
      ;;
    *)
      prompt="$prompt [y|n] "
      ;;
  esac

  while true; do
    txtBoldWhite "$prompt"
    read -n 1 resp
    case "$resp" in
      [nN])
        echo && return 1
        ;;
      [yY])
        echo && return 0
        ;;
      *)
        if [ "$default" == "no" ]; then
          return 1
        elif [ "$default" == "yes" ]; then
          return 0
        else
          txtRed "Yes or no?" "nl"
        fi
    esac
  done
}

#
# returns true if a variable is defined (set) and value's length > 0
# returns false otherwise
#
function isValid {
  ! [[ -z "$1" ]]
}

#
# returns true if the argument is an existing program
# returns false otherwise
#
function isInstalled {
  type "$1" >/dev/null 2>&1 || { return 1; }
}

#
# returns 0 if the global variable GLOBAL_CONTINUE is true or unset
# return 1 otherwise.
# If a parameter is passed, it is used instead of GLOBAL_CONTINUE
#
function shouldContinue {
  local flag=$GLOBAL_CONTINUE

  if isValid "$1"; then
{'fraction_non_alphanumeric': 0.16456456456456456, 'fraction_numerical': 0.01701701701701702, 'mean_word_length': 2.563480741797432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '203054', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1821, 'n_words': 542}