# shellcheck shell=sh

# unset GLOBSORT, before anything else is sourced
# This variable is part of bash >= 5.3
# The rationale is that the user should always be able
# to expect that the snippets be processed in a deterministic order.
unset -v GLOBSORT

# The profile.pre file is intended to allow optionally setting or overriding PATH
# or other variables for users potentially using the termux bash package
# outside of the Termux app in a way that does not require editing etc/profile,
# so that etc/profile can be upgraded by pkg upgrade updates to the bash package
# for that usecase without the user having to always select to not overwrite it
# during the upgrade
if [ -f "/data/data/com.termux/files/usr/etc/profile.pre" ] ; then
    # shellcheck source=/data/data/com.termux/files/usr/etc/profile.pre
    . "/data/data/com.termux/files/usr/etc/profile.pre"
fi

if [ -d "/data/data/com.termux/files/usr/etc/profile.d/" ]; then
    for i in "/data/data/com.termux/files/usr/etc/profile.d"/*.sh; do
        # shellcheck source=/dev/null
        [ -r "$i" ] && . "$i"
    done
    unset i
fi

# Source global bash config, when interactive but not posix or sh mode
if [ -n "${BASH:-}" ] && \
    [ -n "${PS1:-}" ] && \
    [ -z "${POSIXLY_CORRECT:-}" ] && \
    [ "${0#-}" != "sh" ] && \
    [ -r "/data/data/com.termux/files/usr/etc/bash.bashrc" ]; then
        # shellcheck source=/data/data/com.termux/files/usr/etc/bash.bashrc
        . "/data/data/com.termux/files/usr/etc/bash.bashrc"
    # The ~/.bashrc is only automatically sourced if
    # bash is run as interactive but not a login_shell.
    # This tends to be perceived as a bug,
    # so we source it here if both conditions are met.
    if shopt -q login_shell && [ -f ~/.bashrc ]; then
        . ~/.bashrc
    fi
fi
# vim: set noet ft=sh tw=4 sw=4 ff=unix
