<commit_before># shellcheck shell=bash

# This file is both valid Shell script and Python module.
#
# It can be sourced in shell:
# $ source _shell.py
#
# And it can be imported in Python:
# $ python -c 'import _shell; print(_shell.shellsrc)'

"""":

# Dependencies
#
#   readlink (or greadlink)
#   basename
#   cat
#   uname
#   sed
#   find (for completions)
#
# Exported variables
#
#   LUAMB_ACTIVE_ENV
#       A name of the active environment or an empty string.
#
# Global variables
#
#   __luamb_readlink
#       A name of the readlink binary ('readlink' or 'greadlink').
#
#   __luamb_orig_ps1
#       The original value of the PS1 variable.
#       Unset if no active environment.
#
# Functions (in addition to those explicitly declared at the top level)
#
#    __luamb_orig_deactivate
#       The renamed original 'deactivate-lua'.
#       Unset if no active environment.


__luamb_check_exists() {
    type "$@" > /dev/null 2>&1
}


__luamb_is_active() {
    __luamb_check_exists deactivate-lua
}


__luamb_wrap_deactivate_function() {
    local __luamb_orig_deactivate_code
    __luamb_orig_deactivate_code=$(typeset -f deactivate-lua | \
        sed 's/deactivate-lua/__luamb_orig_deactivate/g')
    eval "$__luamb_orig_deactivate_code"
    deactivate-lua() {
        __luamb_off
    }
}


__luamb_on() {
    local env_name
    # tricky way to prevent slashes in env name
    env_name=$(basename "$1")
    local env_path
    env_path=$($__luamb_readlink -e "$LUAMB_DIR/$env_name")
    if [ ! -d "$env_path" ]; then
        echo "environment doesn't exist: $env_name"
        return 1
    fi
    if __luamb_is_active; then
        __luamb_off
    fi
    __luamb_orig_ps1=$PS1
    PS1="($env_name) $__luamb_orig_ps1"
    LUAMB_ACTIVE_ENV=$env_name
    # shellcheck disable=SC1090
    source "$env_path/bin/activate"
    __luamb_wrap_deactivate_function
    if [ -f "$env_path/.project" ]; then
        # shellcheck disable=SC2164
        cd "$(cat "$env_path/.project")"<commit_msg>Check env name in shell script<commit_after># shellcheck shell=bash

# This file is both valid Shell script and Python module.
#
# It can be sourced in shell:
# $ source _shell.py
#
# And it can be imported in Python:
# $ python -c 'import _shell; print(_shell.shellsrc)'

"""":

# Dependencies
#
#   readlink (or greadlink)
#   cat
#   uname
#   sed
#   find (for completions)
#
# Exported variables
#
#   LUAMB_ACTIVE_ENV
#       A name of the active environment or an empty string.
#
# Global variables
#
#   __luamb_readlink
#       A name of the readlink binary ('readlink' or 'greadlink').
#
#   __luamb_orig_ps1
#       The original value of the PS1 variable.
#       Unset if no active environment.
#
# Functions (in addition to those explicitly declared at the top level)
#
#    __luamb_orig_deactivate
#       The renamed original 'deactivate-lua'.
#       Unset if no active environment.


__luamb_check_exists() {
    type "$@" > /dev/null 2>&1
}


__luamb_is_active() {
    __luamb_check_exists deactivate-lua
}


__luamb_check_env_name() {
    if [ "${1}" = '.' ] || [ "${1}" = '..' ] || [ -z "${1##*/*}" ]; then
        echo "invalid env name: '${1}'"
        return 1
    fi
}


__luamb_wrap_deactivate_function() {
    local __luamb_orig_deactivate_code
    __luamb_orig_deactivate_code=$(typeset -f deactivate-lua | \
        sed 's/deactivate-lua/__luamb_orig_deactivate/g')
    eval "$__luamb_orig_deactivate_code"
    deactivate-lua() {
        __luamb_off
    }
}


__luamb_on() {
    local env_name=$1
    __luamb_check_env_name "$env_name" || return 1
    local env_path
    env_path=$($__luamb_readlink -e "$LUAMB_DIR/$env_name")
    if [ ! -d "$env_path" ]; then
        echo "environment doesn't exist: $env_name"
        return 1
    fi
    if __luamb_is_active; then
        __luamb_off
    fi
    __luamb_orig_ps1=$PS1
    PS1="($env_name) $__luamb_orig_ps1"
    LUAMB_ACTIVE_ENV=$env_name
    # shellcheck disable=SC1090
    source "$env_path/bin/activate"
    __luamb_wrap_deactivate_function
    if [ -f "$env_path/.project" ]; then
        # shellcheck disable=SC2164
        cd "$(cat "$env_path/.project")"
{'fraction_non_alphanumeric': 0.10807543520309477, 'fraction_numerical': 0.010154738878143133, 'mean_word_length': 3.0798816568047336, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, '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': '2315464', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1443, 'n_words': 362}