<commit_before>#!/bin/bash
#
# My thanks to Creationix. This script is almost a verbatim copy of
# the install script for NVM (https://github.com/creationix/nvm).

NENV_DIR="$HOME/.cdenv"
GITHUB_REPO_URL="https://github.com/croach/cdenv.git"
NENV_RAW_FILE_URL="https://raw.github.com/croach/cdenv/master/cdenv.sh"

if ! hash git 2>/dev/null; then
  if [ -d "$NENV_DIR" ]; then
    echo "=> cdenv is already installed in $NENV_DIR, trying to update"
    echo -ne "\r=> "
    cd $NENV_DIR && rm cdenv.sh && curl -O $NENV_RAW_FILE_URL
  else
    # Cloning to $NENV_DIR
    mkdir "$NENV_DIR" && cd "$NENV_DIR" && curl -O $NENV_RAW_FILE_URL
  fi
else
  if [ -d "$NENV_DIR" ]; then
    echo "=> cdenv is already installed in $NENV_DIR, trying to update"
    echo -ne "\r=> "
    cd $NENV_DIR && git pull
  else
    # Cloning to $NENV_DIR
    git clone $GITHUB_REPO_URL $NENV_DIR
  fi
fi

# Detect profile file
if [ ! -z "$1" ]; then
  PROFILE="$1"
else
  if [ -f "$HOME/.bashrc" ]; then
    PROFILE="$HOME/.bashrc"
  elif [ -f "$HOME/.zshrc" ]; then
    PROFILE="$HOME/.zshrc"
  elif [ -f "$HOME/.profile" ]; then
    PROFILE="$HOME/.profile"
  fi
fi

SOURCE_STR=$(cat <<EOF
if [[ -f "$HOME/.cdenv/cdenv.sh" ]]; then
  source "$HOME/.cdenv/cdenv.sh"

  # Uncomment the following line if you want virtual environments
  # activated/deactivted as you cd into/out of them.
  # alias cd="_cdenv_cd"

  # Uncomment the following line if you want to try to check for a
  # virtual environment in the current directory (and activate it)
  # whenever a new shell session is created.
  # cdenv activate
fi
EOF
)

if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
  if [ -z $PROFILE ]; then
    echo "=> Profile not found. Tried $HOME/.bash_profile and $HOME/.profile"
  else
    echo "=> Profile $PROFILE not found"
  fi
  echo "=> Run this script again after running the following:"
  echo<commit_msg>Updated install.sh to work with the user's current shell<commit_after>#!/bin/bash
#
# My thanks to Creationix. This script is almost a verbatim copy of
# the install script for NVM (https://github.com/creationix/nvm).

CDENV_DIR="$HOME/.cdenv"
GITHUB_REPO_URL="https://github.com/croach/cdenv.git"
NENV_RAW_FILE_URL="https://raw.github.com/croach/cdenv/master/cdenv.sh"

if ! hash git 2>/dev/null; then
  if [ -d "$CDENV_DIR" ]; then
    echo "=> cdenv is already installed in $CDENV_DIR, trying to update"
    echo -ne "\r=> "
    cd $CDENV_DIR && rm cdenv.sh && curl -O $NENV_RAW_FILE_URL
  else
    # Cloning to $CDENV_DIR
    mkdir "$CDENV_DIR" && cd "$CDENV_DIR" && curl -O $NENV_RAW_FILE_URL
  fi
else
  if [ -d "$CDENV_DIR" ]; then
    echo "=> cdenv is already installed in $CDENV_DIR, trying to update"
    echo -ne "\r=> "
    cd $CDENV_DIR && git pull
  else
    # Cloning to $CDENV_DIR
    git clone $GITHUB_REPO_URL $CDENV_DIR
  fi
fi

# Get the name of the user's current shell
shell="$(basename $SHELL)"

# Detect profile file for the user's shell
if [ -f "$HOME/.${shell}rc" ]; then
  PROFILE="$HOME/.${shell}rc"
elif [ -f "$HOME/.${shell}_profile" ]; then
  PROFILE = "$HOME/.${shell}_profile"
elif [ -f "$HOME/.profile" ]; then
  PROFILE="$HOME/.profile"
fi

SOURCE_STR=$(cat <<EOF
if [[ -f "$HOME/.cdenv/cdenv.sh" ]]; then
  source "$HOME/.cdenv/cdenv.sh"

  # Uncomment the following line if you want virtual environments
  # activated/deactivted as you cd into/out of them.
  # alias cd="_cdenv_cd"

  # Uncomment the following line if you want to try to check for a
  # virtual environment in the current directory (and activate it)
  # whenever a new shell session is created.
  # cdenv activate
fi
EOF
)

if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
  if [ -z $PROFILE ]; then
    echo "=> Profile not found. Tried $HOME/.bash_profile and $HOME/.profile"
  else
    echo "=> Profile $PROFILE not found"
  fi
  echo "=> Run this script again after running the following:"
  echo
{'fraction_non_alphanumeric': 0.1381258023106547, 'fraction_numerical': 0.0010269576379974327, 'mean_word_length': 3.286028602860286, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 6, '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': '7673613', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1381, 'n_words': 445}