<commit_before>#!/usr/bin/env bash

SELF=$0
COMMAND=$1

usage() {
    echo "Usage: $SELF <command>" 1>&2
}

realpath() {
    [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

findDotEnv() {
    FULLPATH=`realpath $1`
    if [ -f "$FULLPATH" ]; then
        PARENTPATH=`dirname $FULLPATH`
    else
        PARENTPATH=$PWD
    fi

    while [ "$PARENTPATH" != "/" ]; do
        CANDIDATE="${PARENTPATH}/.env"
        if [ -f "$CANDIDATE" ]; then
            echo "$CANDIDATE"
            return 0
        fi
        PARENTPATH=`dirname $PARENTPATH`
    done

    # fallback
    echo '.env'
}

splitPathIntoParts() {
    saveIFS=$IFS
    IFS='/'
    PATHPARTS=($1)
    IFS=$saveIFS
}

if [ "$COMMAND" == "" ] || [ "$COMMAND" == "-h" ]; then
    usage
    exit 1
fi

DOTENV=`findDotEnv "$COMMAND"`
if [ ! -f "$DOTENV" ]; then
    echo "Error: couldn't find .env" 1>&2
    exit 1
fi

TMPENV=`mktemp /tmp/dotenv.XXXX`

touch $TMPENV
chmod 600 $TMPENV

while read line; do
    echo export $line
done < $DOTENV > $TMPENV

source $TMPENV
rm -f $TMPENV

"${@:1}"
<commit_msg>Fixed whitespace bug<commit_after>#!/usr/bin/env bash

SELF=$0
COMMAND=$1

usage() {
    echo "Usage: $SELF <command>" 1>&2
}

realpath() {
    [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

findDotEnv() {
    FULLPATH=`realpath $1`
    if [ -f "$FULLPATH" ]; then
        PARENTPATH=`dirname $FULLPATH`
    else
        PARENTPATH=$PWD
    fi

    while [ "$PARENTPATH" != "/" ]; do
        CANDIDATE="${PARENTPATH}/.env"
        if [ -f "$CANDIDATE" ]; then
            echo "$CANDIDATE"
            return 0
        fi
        PARENTPATH=`dirname $PARENTPATH`
    done

    # fallback
    echo '.env'
}

splitPathIntoParts() {
    saveIFS=$IFS
    IFS='/'
    PATHPARTS=($1)
    IFS=$saveIFS
}

if [ "$COMMAND" == "" ] || [ "$COMMAND" == "-h" ]; then
    usage
    exit 1
fi

DOTENV=`findDotEnv "$COMMAND"`
if [ ! -f "$DOTENV" ]; then
    echo "Error: couldn't find .env" 1>&2
    exit 1
fi

TMPENV=`mktemp /tmp/dotenv.XXXX`

touch $TMPENV
chmod 600 $TMPENV

while read line; do
    # trim whitespace
    line=`echo "$line" | sed -e 's/^ *//g' -e 's/ *$//g'`
    if [ "$line" != "" ]; then
        echo export $line
    fi
done < $DOTENV > $TMPENV

source $TMPENV
rm -f $TMPENV

"${@:1}"

{'fraction_non_alphanumeric': 0.18631346578366445, 'fraction_numerical': 0.015894039735099338, 'mean_word_length': 2.2936046511627906, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3759369', 'n_tokens_mistral': 938, 'n_tokens_neox': 898, 'n_words': 215}