<commit_before>su() {
  # su: Do sudo to a command, or do sudo to the last typed command if no argument given
  if [[ $# == 0 ]]; then
    sudo "$(history -p '!!')"
  else
    sudo "$@"
  fi
}

withBackoff() {
  # Retries a command a configurable number of times with backoff.
  # (http://stackoverflow.com/questions/8350942/how-to-re-run-the-curl-command-automatically-when-the-error-occurs/8351489#8351489)
  #
  # The retry count is given by ATTEMPTS (default 5), the initial backoff
  # timeout is given by TIMEOUT in seconds (default 1.)
  #
  # Successive backoffs double the timeout.
  #
  # Then use it in conjunction with any command that properly sets a failing exit code:
  #
  # with_backoff curl 'http://monkeyfeathers.example.com/'
  # #######################################################################
  local max_attempts=${ATTEMPTS-5}
  local timeout=${TIMEOUT-1}
  local attempt=0
  local exitCode=0

  while ((attempt < max_attempts)); do
    set +e
    "$@"
    exitCode=$?
    set -e

    if [[ ${exitCode} == 0 ]]; then
      break
    fi

    echo "Failure! Retrying in ${timeout}.." 1>&2
    sleep "${timeout}"
    attempt=$((attempt + 1))
    timeout=$((timeout * 2))
  done

  if [[ ${exitCode} != 0 ]]; then
    echo "You've failed me for the last time! ($*)" 1>&2
  fi
  return ${exitCode}
}

# type command differs between BASH and ZSH.
if [[ $currentShell == "zsh" ]]; then
  halp() {
    # A little helper for man/alias/function info
    # http://brettterpstra.com/2016/05/18/shell-tricks-halp-a-universal-help-tool/
    # Edited to run 'SCRIPT.sh -h' for my own personal scripts

    local apro=0
    local helpstring="Usage: halp COMMAND"
    local opt OPTIND

    OPTIND=1
    while getopts "kh" opt; do
      case ${opt} in
        k) apro=1 ;;
        h)
          echo -e "${helpstring}"
          return
          ;;
        *) return 1 ;;
      esac
    done
    shift $((OPTIND - 1))

    if [ $# -ne 1 ]; then
      echo -e "${helpstring}"
      return 1
    fi

    local cmd
    local cmdtest
    cmd="${1}"
    cmdtest="$(type -w "${cmd}" | awk -F': ' '{print $2}')"

    if [ -z "${cmdtest}" ]; then
      echo -e "${YELLOW}'$cmd' is not a command${RESET}"
      if [[ "$apro" == 1 ]]; then
        man -k "${cmd}"
      else
        return 1
      fi
    fi

    if [[ "${cmdtest}" == "command" ]]; then
      location=$(command -v "$cmd")
      bindir="${HOME}/bin/${cmd}"
      if [[ "${location}" == "${bindir}" ]]; then
        echo -e "${YELLOW}${cmd} is a custom script:  ${RESET}\n"
        $cmd -h
      else
        man "${cmd}"
      fi
    elif [[ "${cmdtest}" == "alias" ]]; then
      echo -ne "${YELLOW}${cmd} is an alias:  ${RESET}"
      alias "${cmd}" | sed -E "s/alias $cmd='(.*)'/\1/"
    elif [[ "${cmdtest}" == "builtin" ]]; then
      echo -ne "${YELLOW}${cmd} is a builtin command:  ${RESET}"
      man "${cmd}"
    elif [[ "${cmdtest}" == "function" ]]; then
      echo -e "${YELLOW}${cmd} is a function:  ${RESET}"
      type -f "${cmd}" | tail -n +1
    fi
  }
else
  halp() {
    # A little helper for man/alias/function info
    # http://brettterpstra.com/2016/05/18/shell-tricks-halp-a-universal-help-tool/
    # Edited to run 'SCRIPT.sh -h' for my own personal scripts

    local apro=0
    local helpstring="Usage: halp COMMAND"
    local opt OPTIND

    OPTIND=1
    while getopts "kh" opt; do<commit_msg>Add commonly forgotten commands to halp()<commit_after>su() {
  # su: Do sudo to a command, or do sudo to the last typed command if no argument given
  if [[ $# == 0 ]]; then
    sudo "$(history -p '!!')"
  else
    sudo "$@"
  fi
}

withBackoff() {
  # Retries a command a configurable number of times with backoff.
  # (http://stackoverflow.com/questions/8350942/how-to-re-run-the-curl-command-automatically-when-the-error-occurs/8351489#8351489)
  #
  # The retry count is given by ATTEMPTS (default 5), the initial backoff
  # timeout is given by TIMEOUT in seconds (default 1.)
  #
  # Successive backoffs double the timeout.
  #
  # Then use it in conjunction with any command that properly sets a failing exit code:
  #
  # with_backoff curl 'http://monkeyfeathers.example.com/'
  # #######################################################################
  local max_attempts=${ATTEMPTS-5}
  local timeout=${TIMEOUT-1}
  local attempt=0
  local exitCode=0

  while ((attempt < max_attempts)); do
    set +e
    "$@"
    exitCode=$?
    set -e

    if [[ ${exitCode} == 0 ]]; then
      break
    fi

    echo "Failure! Retrying in ${timeout}.." 1>&2
    sleep "${timeout}"
    attempt=$((attempt + 1))
    timeout=$((timeout * 2))
  done

  if [[ ${exitCode} != 0 ]]; then
    echo "You've failed me for the last time! ($*)" 1>&2
  fi
  return ${exitCode}
}

# type command differs between BASH and ZSH.
if [[ $currentShell == "zsh" ]]; then
  halp() {
    # A little helper for man/alias/function info
    # http://brettterpstra.com/2016/05/18/shell-tricks-halp-a-universal-help-tool/
    # Edited to run 'SCRIPT.sh -h' for my own personal scripts

    local apro=0
    local helpstring="Usage: halp COMMAND

    ${bold}Commonly forgotten commands:${reset}
      cleanDS             Remove .DS_Store files
      finderPath          Gets the frontmost path from the Finder
      lips                Prints local and external IP addresses
      ql                  Opens any file in MacOS Quicklook Preview
      "
    local opt OPTIND

    OPTIND=1
    while getopts "kh" opt; do
      case ${opt} in
        k) apro=1 ;;
        h)
          echo -e "${helpstring}"
          return
          ;;
        *) return 1 ;;
      esac
    done
    shift $((OPTIND - 1))

    if [ $# -ne 1 ]; then
      echo -e "${helpstring}"
      return 1
    fi

    local cmd
    local cmdtest
    cmd="${1}"
    cmdtest="$(type -w "${cmd}" | awk -F': ' '{print $2}')"

    if [ -z "${cmdtest}" ]; then
      echo -e "${YELLOW}'$cmd' is not a command${RESET}"
      if [[ "$apro" == 1 ]]; then
        man -k "${cmd}"
      else
        return 1
      fi
    fi

    if [[ "${cmdtest}" == "command" ]]; then
      location=$(command -v "$cmd")
      bindir="${HOME}/bin/${cmd}"
      if [[ "${location}" == "${bindir}" ]]; then
        echo -e "${YELLOW}${cmd} is a custom script:  ${RESET}\n"
        $cmd -h
      else
        man "${cmd}"
      fi
    elif [[ "${cmdtest}" == "alias" ]]; then
      echo -ne "${YELLOW}${cmd} is an alias:  ${RESET}"
      alias "${cmd}" | sed -E "s/alias $cmd='(.*)'/\1/"
    elif [[ "${cmdtest}" == "builtin" ]]; then
      echo -ne "${YELLOW}${cmd} is a builtin command:  ${RESET}"
      man "${cmd}"
    elif [[ "${cmdtest}" == "function" ]]; then
      echo -e "${YELLOW}${cmd} is a function:  ${RESET}"
      type -f "${cmd}" | tail -n +1
    fi
  }
else
  halp() {
    # A little helper for man/alias/function info
    # http://brettterpstra.com/2016/05/18/shell-tricks-halp-a-universal-help-tool/
    # Edited to run 'SCRIPT.sh -h' for my own personal scripts

    local apro=0
    local helpstring="Usage: halp COMMAND

    ${bold}Commonly forgotten commands:${reset}
      cleanDS             Remove .DS_Store files
      finderPath          Gets the frontmost path from the Finder
      lips                Prints local and external IP addresses
      ql                  Opens any file in MacOS Quicklook Preview
      "
    local opt OPTIND

    OPTIND=1
    while getopts "kh" opt; do
{'fraction_non_alphanumeric': 0.1705342687533729, 'fraction_numerical': 0.01807879114948732, 'mean_word_length': 2.3331834532374103, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4407493', 'n_tokens_mistral': 2554, 'n_tokens_neox': 2391, 'n_words': 766}