<commit_before># Appends the first argument to the `PATH` if it exists and is a directory.
append-path-entry () {
    dir=$1

    if [ -d $dir ]; then
        PATH="$PATH:$dir"
    fi
}

append-path-entry $HOME/bin
append-path-entry $SOURCE_DIR/local-only/bin

export PATH<commit_msg>Ensure /usr/local/bin is ahead of /usr/bin in the PATH<commit_after># The default on OS X is for `/usr/local/bin` to be in the PATH, but *after* `/usr/bin`. Homebrew
# does not work if /usr/local/bin is after and OS X includes that in the OS itself, like emacs. One
# can edit `/etc/paths`, but I would rather not edit system files if I can avoid it. So the
# following code allows me to parse the `PATH`, find the two paths relative to each other, ensure
# that `/usr/local/bin` is first and then remove any duplicates when I'm done while continuing to
# maintain relative order of the first instance of any entry.
#
# Oh, and I wanted to make it so this would work with only POSIX-guaranteed utilities.

# Appends the first argument to the `PATH` iff:
#
# * It exists
# * Is a directory
# * Is not already in PATH
__append-path-entry () {
    dir=$1

    if [ -d $dir ]; then
        case ":$PATH:" in
            *":$dir:"*) :;;
            *) PATH="$PATH:$dir";;
        esac
    fi
}

# Escapes the first argument to be used as a regular expression.
__escape-string () {
    text=$1
    echo $text | sed -e 's/[\/&]/\\&/g'
}

# Splits the first argument by the second.
__split-string () {
    text=$1
    sep=$2

    echo $text | tr $2 '\n'
}

# Gets the index of the first instance of the second argument within the first.
__get-index () {
    text=$1
    search=`__escape-string $2`

    __split-string $text ':' | awk "/$search/{print NR - 1}" | head -n 1
}

if [[ `__get-index $PATH /usr/local/bin` -gt `__get-index $PATH /usr/bin` ]]; then
    PATH="/usr/local/bin:$PATH"
fi

__append-path-entry $HOME/bin
__append-path-entry $SOURCE_DIR/local-only/bin

# Remove duplicate path entries
# Taken from: http://unix.stackexchange.com/a/40973/10613
set -f
IFS=:
old_PATH=$PATH:
PATH=
while [ -n "$old_PATH" ]; do
  x=${old_PATH%%:*}
  case $PATH: in
    *:${x}:*) :;;
    *) PATH=$PATH:$x;;
  esac
  old_PATH=${old_PATH#*:}
done
PATH=${PATH#:}
set +f
unset IFS old_PATH x

export PATH
{'fraction_non_alphanumeric': 0.139463264408271, 'fraction_numerical': 0.008798944126704795, 'mean_word_length': 3.0105820105820107, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '71696', 'n_tokens_mistral': 808, 'n_tokens_neox': 772, 'n_words': 288}