# ~/.bashrc # 1. Non-interactive shell check [[ $- != *i* ]] && return # 2. Path Helper (Prevents the "Mega-String" path pollution) # This function only adds a directory if it isn't already there. path_add() { if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then export PATH="$1:$PATH" fi } # Reset to a sane baseline then add your custom paths safely export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" path_add "$HOME/.local/bin" path_add "/usr/local/sbin" path_add "$HOME/bin" path_add "$HOME/go/bin" path_add "/snap/go/current/bin" export SDKMAN_DIR="$HOME/.sdkman" [[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh" # 3. History Settings (Security Audit Optimized) HISTCONTROL=ignoredups:ignorespace shopt -s histappend HISTSIZE=10000 HISTFILESIZE=20000 export HISTTIMEFORMAT="%F %T " # Essential for incident response/forensics PROMPT_COMMAND="history -a" # Save immediately after every command # 4. Prompt & Shell Behavior shopt -s checkwinsize if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi # 5. Completions if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi complete -cf sudo # 6. Load Aliases if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi # 7. NVM Setup (Loaded after Path to avoid conflicts) export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # 8. Login Dashboard echo -e "\n\e[1;32m--- Welcome Jared (Zappy) ---\e[0m" echo "External IP: $(curl -4 -s --max-time 2 https://ifconfig.me || echo 'Offline')" echo "Space left: $(df -h / | awk 'NR==2 {print $4}')" echo -e "\n\e[1;34mQuick Commands:\e[0m" # Filter: Remove internal bash functions (_) and NVM internals ( alias | cut -d'=' -f1 | cut -d' ' -f2; declare -F | cut -d' ' -f3 | grep -vE '^(_|nvm|path_add|start_ssh_agent|__)' ) | sort | xargs echo echo "" # --- Auto-activate Python .venv on cd --- # Activates ./\.venv when present; deactivates when leaving that project tree. # Safe for interactive shells only (your .bashrc already returns early for non-interactive). _venv_auto_activate() { local venv_path="$PWD/.venv" # If we are already in a venv, but we've left its project directory, deactivate it. if [[ -n "${VIRTUAL_ENV:-}" ]]; then # If current dir is NOT under the venv's parent dir, deactivate. local venv_parent venv_parent="$(dirname "$VIRTUAL_ENV")" # .../.venv venv_parent="$(dirname "$venv_parent")" # project root case "$PWD/" in "$venv_parent"/*) ;; # still inside the project *) deactivate 2>/dev/null || true ;; esac fi # If no venv active (or we just deactivated), and this directory has a .venv, activate it. if [[ -z "${VIRTUAL_ENV:-}" && -f "$venv_path/bin/activate" ]]; then # shellcheck disable=SC1090 source "$venv_path/bin/activate" fi } # Wrap cd so it triggers venv auto-activation. cd() { builtin cd "$@" || return _venv_auto_activate } # Also run once for the starting directory when the shell launches. _venv_auto_activate