-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc_core
More file actions
137 lines (124 loc) · 5.38 KB
/
bashrc_core
File metadata and controls
137 lines (124 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# ==============================================================================
# BASHRC CORE - Main Orchestrator
# ==============================================================================
# Central configuration loader for bash-config system.
# This file is typically symlinked to ~/.bashrc_core and sourced from ~/.bashrc.
#
# Load Order:
# 1. bash_logging - Color constants and bc_log_* functions (loaded first)
# 2. secrets/bash_secrets.sh - Sensitive credentials (gitignored)
# 3. bash_aliases - Shared aliases
# 4. bash_exports - Shared environment variables
# 5. bash_prompt - Prompt configuration
# 6. bash_tools - Utility functions
# 7. bash_ssh - SSH management
# 8. bash_history - History management
# 9. bash_config_update - bash-config repo self-update (bc_check_updates, bc_update_config)
# 10. specialisations/bashrc_* - Machine-specific configuration
#
# Environment Variables:
# BASH_SPECIALISATION - Set in ~/.bashrc to select specialisation
# BASH_CONFIG_DIR - Auto-detected directory of this config
# BASH_CONFIG_DEBUG - Set to "true" to enable debug logging
# ==============================================================================
export BASH_CONFIG_VERSION="2.0.0"
# ==============================================================================
# PATH RESOLUTION
# ==============================================================================
# Resolve the real path of this script (handles symlinks)
__realpath() {
local path="$1"
while [ -L "$path" ]; do
path="$(readlink "$path")"
[[ "$path" != /* ]] && path="$(dirname "$1")/$path"
done
cd "$(dirname "$path")" && pwd
}
export BASH_CONFIG_DIR="${BASH_CONFIG_DIR:-$(__realpath "${BASH_SOURCE[0]}")}"
# Validate configuration directory
if [[ ! -d "$BASH_CONFIG_DIR" ]]; then
echo "[ERROR] BASH_CONFIG_DIR not found: $BASH_CONFIG_DIR" >&2
return 1 2>/dev/null || exit 1
fi
# ==============================================================================
# MODULE LOADER
# ==============================================================================
# Source a file if it exists, with optional description for warnings
bc_source_if_exists() {
local file="$1"
local description="${2:-$file}"
if [[ -f "$file" ]]; then
source "$file"
else
echo "[WARN] $description not found: $file" >&2
fi
}
# Load core modules
bc_source_if_exists "$BASH_CONFIG_DIR/bash_logging" "Logging"
bc_source_if_exists "$BASH_CONFIG_DIR/secrets/bash_secrets.sh" "Secrets file"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_aliases" "Aliases"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_exports" "Exports"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_prompt" "Prompt configuration"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_tools" "Tools and functions"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_certs" "Certificate management"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_ssh" "SSH management"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_history" "History management"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_update" "Update utilities"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_config_update" "Config self-update"
bc_source_if_exists "$BASH_CONFIG_DIR/bash_project" "Project workspace management"
# ==============================================================================
# SPECIALISATION LOADER
# ==============================================================================
if [[ -n "${BASH_SPECIALISATION:-}" ]]; then
spec_file="$BASH_CONFIG_DIR/specialisations/bashrc_$BASH_SPECIALISATION"
case "$BASH_SPECIALISATION" in
frostpaw|diamond|asteria)
if [[ -f "$spec_file" ]]; then
source "$spec_file"
else
echo "[ERROR] Specialisation file not found: $spec_file" >&2
fi
;;
*)
echo "[ERROR] Unknown specialisation: $BASH_SPECIALISATION" >&2
echo "[INFO] Available specialisations: frostpaw, diamond, asteria" >&2
;;
esac
fi
# ==============================================================================
# INITIALIZATION
# ==============================================================================
# Initialize prompt and history PROMPT_COMMAND
# set_prompt runs once to build the initial PS1, then PROMPT_COMMAND is set so
# it re-runs before every prompt. bc_history_init() appends its own hooks
# *after* this assignment, so ordering is guaranteed correct.
set_prompt
PROMPT_COMMAND="set_prompt"
# Load bash-preexec so atuin's precmd/preexec hooks are active.
# Delegates to bc_source_bash_preexec (defined in bash_history) which checks
# system package paths, $HOME install, and the repo submodule in order.
if declare -f bc_source_bash_preexec >/dev/null 2>&1; then
bc_source_bash_preexec
fi
if declare -f bc_history_init >/dev/null 2>&1; then
bc_history_init
fi
# Interactive shell features
if [[ $- == *i* ]]; then
# Show system info on login
bc_ff
# Daily update check (only on real terminals, not scripts/pipes)
if [[ -t 0 ]]; then
update_check_file="$BASH_CONFIG_DIR/.last_update_check"
current_date=$(date +%Y%m%d)
if [[ ! -f "$update_check_file" ]] || [[ "$(cat "$update_check_file" 2>/dev/null)" != "$current_date" ]]; then
bc_check_updates silent
check_result=$?
if [[ $check_result -eq 2 ]]; then
bc_check_updates notify
fi
echo "$current_date" > "$update_check_file"
fi
fi
fi