<commit_before>#!/bin/sh

_koopa_add_config_link() { # {{{1
    # """
    # Add a symlink into the koopa configuration directory.
    # @note Updated 2021-05-24.
    # """
    local config_prefix dest_file dest_name ln mkdir rm source_file
    [ "$#" -eq 2 ] || return 1
    source_file="${1:?}"
    dest_name="${2:?}"
    config_prefix="$(_koopa_config_prefix)"
    dest_file="${config_prefix}/${dest_name}"
    [ -L "$dest_file" ] && return 0
    ln="$(_koopa_locate_ln)"
    mkdir="$(_koopa_locate_mkdir)"
    rm="$(_koopa_locate_rm)"
    "$mkdir" -p "$config_prefix"
    "$rm" -fr "$dest_file"
    "$ln" -fns "$source_file" "$dest_file"
    return 0
}

_koopa_check_os() {
    # """
    # Check that operating system is supported.
    # @note Updated 2021-05-07.
    # """
    case "$(uname -s)" in
        Darwin | \
        Linux)
            ;;
        *)
            _koopa_warning 'Unsupported operating system.'
            return 1
            ;;
    esac
    return 0
}

_koopa_check_shell() { # {{{1
    # """
    # Check that current shell is supported, and export 'KOOPA_SHELL' variable.
    # @note Updated 2021-05-24.
    # """
    local shell shell_name
    shell="$(_koopa_locate_shell)"
    KOOPA_SHELL="$shell"
    export KOOPA_SHELL
    shell_name="$(_koopa_shell_name)"
    SHELL="$shell_name"
    export SHELL
    case "$shell_name" in
        ash | \
        bash | \
        busybox | \
        dash | \
        zsh)
            ;;
        *)
            if _koopa_is_interactive
            then
                >&2 cat << END
WARNING: Failed to activate koopa in the current shell.

    Recommended: Bash or Zsh.
    Also supported: Ash, Busybox, Dash.

    KOOPA_SHELL : '${shell}'
          SHELL : '${SHELL:-}'
              - : '${-}'
              0 : '${0}'
              \$ : '${$}'

    Change to Bash:
        > chsh -s /bin/bash

    Change to Zsh:
        > chsh -s /bin/zsh

END
            fi
            return 1
            ;;
    esac
    return 0
}

_koopa_duration_start() { # {{{1
    # """
    # Start activation duration timer.
    # @note Updated 2021-05-24.
    # """
    local bc date
    bc="$(_koopa_locate_bc)"
    date="$(_koopa_locate_date)"
    KOOPA_DURATION_START="$("$date" -u '+%s%3N')"
    export KOOPA_DURATION_START
    return 0
}

_koopa_duration_stop() { # {{{1
    # """
    # Stop activation duration timer.
    # @note Updated 2021-05-24.
    # """
    local bc date duration start stop
    bc="$(_koopa_locate_bc)"
    date="$(_koopa_locate_date)"
    start="${KOOPA_DURATION_START:?}"
    stop="$("$date" -u '+%s%3N')"
    duration="$( \
        _koopa_print "${stop}-${start}" \
        | "$bc" \
    )"
    _koopa_dl 'duration' "${duration} ms"
    unset -v KOOPA_DURATION_START
    return 0
}

_koopa_exec_dir() { # {{{1
    # """
    # Execute multiple shell scripts in a directory.
    # @note Updated 2020-07-23.
    # """
    local dir file
    dir="${1:?}"
    [ -d "$dir" ] || return 0
    for file in "${dir}/"*'.sh'
    do<commit_msg>Simplify activation<commit_after>#!/bin/sh

_koopa_add_config_link() { # {{{1
    # """
    # Add a symlink into the koopa configuration directory.
    # @note Updated 2021-05-24.
    # """
    local config_prefix dest_file dest_name ln mkdir rm source_file
    [ "$#" -eq 2 ] || return 1
    source_file="${1:?}"
    dest_name="${2:?}"
    config_prefix="$(_koopa_config_prefix)"
    dest_file="${config_prefix}/${dest_name}"
    [ -L "$dest_file" ] && return 0
    ln="$(_koopa_locate_ln)"
    mkdir="$(_koopa_locate_mkdir)"
    rm="$(_koopa_locate_rm)"
    "$mkdir" -p "$config_prefix"
    "$rm" -fr "$dest_file"
    "$ln" -fns "$source_file" "$dest_file"
    return 0
}

_koopa_check_os() {
    # """
    # Check that operating system is supported.
    # @note Updated 2021-05-07.
    # """
    case "$(uname -s)" in
        Darwin | \
        Linux)
            ;;
        *)
            _koopa_warning 'Unsupported operating system.'
            return 1
            ;;
    esac
    return 0
}

_koopa_check_shell() { # {{{1
    # """
    # Check that current shell is supported, and export 'KOOPA_SHELL' variable.
    # @note Updated 2021-05-24.
    # """
    local shell shell_name
    shell="$(_koopa_locate_shell)"
    KOOPA_SHELL="$shell"
    export KOOPA_SHELL
    shell_name="$(_koopa_shell_name)"
    SHELL="$shell_name"
    export SHELL
    case "$shell_name" in
        ash | \
        bash | \
        busybox | \
        dash | \
        zsh)
            ;;
        *)
            if _koopa_is_interactive
            then
                >&2 cat << END
WARNING: Failed to activate koopa in the current shell.

    Recommended: Bash or Zsh.
    Also supported: Ash, Busybox, Dash.

    KOOPA_SHELL : '${shell}'
          SHELL : '${SHELL:-}'
              - : '${-}'
              0 : '${0}'
              \$ : '${$}'

    Change to Bash:
        > chsh -s /bin/bash

    Change to Zsh:
        > chsh -s /bin/zsh

END
            fi
            return 1
            ;;
    esac
    return 0
}

_koopa_duration_start() { # {{{1
    # """
    # Start activation duration timer.
    # @note Updated 2021-05-25.
    # """
    local brew_prefix date
    date='date'
    if _koopa_is_macos
    then
        brew_prefix="$(_koopa_homebrew_prefix)"
        date="${brew_prefix}/opt/coreutils/bin/gdate"
    fi
    KOOPA_DURATION_START="$("$date" -u '+%s%3N')"
    export KOOPA_DURATION_START
    return 0
}

_koopa_duration_stop() { # {{{1
    # """
    # Stop activation duration timer.
    # @note Updated 2021-05-25.
    # """
    local brew_prefix bc date duration start stop
    bc='bc'
    date='date'
    if _koopa_is_macos
    then
        brew_prefix="$(_koopa_homebrew_prefix)"
        bc="${brew_prefix}/opt/bc/bin/bc"
        date="${brew_prefix}/opt/coreutils/bin/gdate"
    fi
    start="${KOOPA_DURATION_START:?}"
    stop="$("$date" -u '+%s%3N')"
    duration="$( \
        _koopa_print "${stop}-${start}" \
        | "$bc" \
    )"
    _koopa_dl 'duration' "${duration} ms"
    unset -v KOOPA_DURATION_START
    return 0
}

_koopa_exec_dir() { # {{{1
    # """
    # Execute multiple shell scripts in a directory.
    # @note Updated 2020-07-23.
    # """
    local dir file
    dir="${1:?}"
    [ -d "$dir" ] || return 0
    for file in "${dir}/"*'.sh'
    do
{'fraction_non_alphanumeric': 0.15241871530531326, 'fraction_numerical': 0.022839016653449642, 'mean_word_length': 2.010023866348449, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3935679', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2224, 'n_words': 487}