#!/usr/bin/env bash
_location=".config/bash/bashrc"

# This file gets run in two cases:
# 1. non-login interactive shell
# 2. remote shell (over ssh or similar)
#
# #2 happens when you run "ssh user@host bash" explicitly.
# In this case, /etc/bash.bashrc has not been previous executed (unlike #1).
#
# Sauce:
#  - https://blog.flowblok.id.au/2013-02/shell-startup-scripts.html
#  - https://heptapod.host/flowblok/shell-startup/-/blob/branch/default/.bashrc

# {{{ <mordu debug system>
# _debug=y # Comment this out to disable debuging.

_blue="\e[34m"
_magenta="\e[35m"
_green="\e[92m"
_cyan="\e[36m"
_white="\e[97m"
_end_color="\e[0m"

# Mordu with location.
_mordu() {
	[ "$_debug" ] && echo -e "${_blue}>>> ${_magenta}Mordu${_cyan}@${_green}${_location}${_cyan}:${_white} $*${_end_color}"
}

# Mordu with location and no new line.
_mordu_n() {
	[ "$_debug" ] && echo -en "${_blue}>>> ${_magenta}Mordu${_cyan}@${_green}${_location}${_cyan}:${_white} $*${_end_color}"
}

# Echo with new line to add completion messages to _mordu_n
_mordu_nl() {
	[ "$_debug" ] && echo -e "${_white}$*${_end_color}"
}

_mordu "Starting script."
# }}} </mordu debug system>

# {{{ === Sourcing env.bash ===
_mordu "Sourcing Env Vars from ~/.config/bash/env.bash."
source "$HOME"/.config/bash/env.bash
_location=".config/bash/bashrc"
_mordu "Finished sourcing Env Vars from ~/.config/bash/env.bash."
# }}} === Sourcing env.bash ===

# {{{ === Interactive Shell Sanity Check ===
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# }}} === Interactive Shell Sanity Check ===

# {{{ === Source System Wide bashrc ===
_mordu "Sourcing /etc/bashrc."
if [ -f /etc/bashrc ]; then
	source /etc/bashrc
fi
_mordu "Finished sourcing /etc/bashrc."
# }}} === Source System Wide bashrc ===

# {{{ === Source interactive.bash ===
_mordu "Sourcing Interactive Shell settings from ~/.config/bash/interactive.bash."
source "$HOME"/.config/bash/interactive.bash
_location=".config/bash/bashrc"
_mordu "Finished sourcing Interactive Shell settings from ~/.config/bash/interactive.bash."
# }}} === Source interactive.bash ===
    
_mordu "Finished script."
