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

DEPS_DIR=~/.local/deps

# Try to dump all dependencies to their respective files
dump-leaves() {
    for dest in "$DEPS_DIR"/*; do
        local m="$(basename "$dest")"

        if which "$m" &>/dev/null; then
            echo "Dumping $m leaves to $dest..."
            local leaves="$(${m}-leaves 2>/dev/null)"
            [ "$leaves" ] && echo "$leaves" > "$dest" ||\
                echo "    ${m}-leaves FAILED!"
        else
            echo "$m not found, skipping..."
        fi
    done
}

# Try to install all dependencies to their respective files
install-leaves() {
    local NORM="\033[0m"
    local RED="\033[0;31m"
    local GREEN="\033[0;32m"
    local YELLOW="\033[0;33m"

    local INSTALLERS=(
        [brew]="brew bundle --file=-"
        [pip]="xargs pip install"
        [npm]="xargs npm install -g"
        [gem]="xargs gem install"
        [luarocks]="xargs luarocks install"
    )

    for src in "$DEPS_DIR"/*; do
        echo
        local m="$(basename "$src")"
        local reqs="$(comm -23 "$src" <(${m}-leaves 2>/dev/null) \
            | sed 's/^/    /')"

        if which "$m" &>/dev/null ||\
                [ "$m" == "AppStore" -a "$(uname)" == "Darwin" ]; then
            if [ "$reqs" ]; then
                echo -e "${GREEN}Installing $m leaves with \`${INSTALLERS[$m]}\`...$NORM"
                echo "$reqs" | ${INSTALLERS[$m]}
            else
                echo -e "${GREEN}$m up to date!$NORM"
            fi
        else
            echo -e "${YELLOW}$m not found, skipping...${NORM}"
        fi
    done

    echo
}

# cd with smart ... handling
cd() {
    local first="${1%%/*}"
    local num
    local rest

    # Only consider if first is all dots
    if [ ! "$(tr -d . <<< "$first")" ]; then
        num="$(wc -c <<< "$first")"
        rest="${1#$first}"
    else
        num=0
    fi

    if [ $num -gt 3 ]; then
        command cd "..$(printf '%0.s/..' $(seq 1 $(($num - 3))))$rest"<commit_msg>add yarn as NODEP_INSTALLER<commit_after>#!/usr/bin/env bash

DEPS_DIR=~/.local/deps

# Try to dump all dependencies to their respective files
dump-leaves() {
    for dest in "$DEPS_DIR"/*; do
        local m="$(basename "$dest")"

        if which "$m" &>/dev/null; then
            echo "Dumping $m leaves to $dest..."
            local leaves="$(${m}-leaves 2>/dev/null)"
            [ "$leaves" ] && echo "$leaves" > "$dest" ||\
                echo "    ${m}-leaves FAILED!"
        else
            echo "$m not found, skipping..."
        fi
    done
}

# Try to install all dependencies to their respective files
install-leaves() {
    local NORM="\033[0m"
    local RED="\033[0;31m"
    local GREEN="\033[0;32m"
    local YELLOW="\033[0;33m"

    local INSTALLERS=(
        [brew]="brew bundle --file=-"
        [pip]="xargs pip install"
        [npm]="xargs npm install -g"
        [gem]="xargs gem install"
        [luarocks]="xargs luarocks install"
    )

    for src in "$DEPS_DIR"/*; do
        echo
        local m="$(basename "$src")"
        local reqs="$(comm -23 "$src" <(${m}-leaves 2>/dev/null) \
            | sed 's/^/    /')"

        if which "$m" &>/dev/null ||\
                [ "$m" == "AppStore" -a "$(uname)" == "Darwin" ]; then
            if [ "$reqs" ]; then
                echo -e "${GREEN}Installing $m leaves with \`${INSTALLERS[$m]}\`...$NORM"
                echo "$reqs" | ${INSTALLERS[$m]}
            else
                echo -e "${GREEN}$m up to date!$NORM"
            fi
        else
            echo -e "${YELLOW}$m not found, skipping...$NORM"
        fi
    done

    # Handle these separately
    local NODEP_INSTALLERS=(
        [yarn]="yarn global add"
    )
    for m in "${!NODEP_INSTALLERS[@]}"; do
        if which "$m" &>/dev/null; then
            echo -e "${GREEN}Installing $m leaves with \`${NODEP_INSTALLERS[$m]}\`...$NORM"
            ${NODEP_INSTALLERS[$m]}
        else
            echo -e "${YELLOW}$m not found, skipping...$NORM"
        fi
    done

    echo
}

# cd with smart ... handling
cd() {
    local first="${1%%/*}"
    local num
    local rest

    # Only consider if first is all dots
    if [ ! "$(tr -d . <<< "$first")" ]; then
        num="$(wc -c <<< "$first")"
        rest="${1#$first}"
    else
        num=0
    fi

    if [ $num -gt 3 ]; then
        command cd "..$(printf '%0.s/..' $(seq 1 $(($num - 3))))$rest"
{'fraction_non_alphanumeric': 0.18546365914786966, 'fraction_numerical': 0.015037593984962405, 'mean_word_length': 1.7575376884422111, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 14, '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': '7570414', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1438, 'n_words': 411}