Repository navigation
Expand file tree
/
Copy pathloader.sh
More file actions
196 lines (154 loc) · 6.82 KB
/
Copy pathloader.sh
File metadata and controls
196 lines (154 loc) · 6.82 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
# ~/.dash/loader.sh
# Main entry point for dash framework
# Source this from your ~/.bashrc
# Prevent double-loading
[[ -n "${DASH_LOADED}" ]] && return 0
# Version
export DASH_VERSION="1.0.0"
export DASH_HOME="${HOME}/.dash"
# Performance tracking (optional)
DASH_LOAD_START=$(date +%s%3N)
#------------------------------------------------------------------------------
# Core Functions
#------------------------------------------------------------------------------
dash_log() {
local level="$1" msg="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] [$level] $msg" >>"${DASH_HOME}/cache/dash.log"
}
dash_info() {
printf "\e[34m[dash]\e[0m %s\n" "$1"
dash_log "INFO" "$1"
}
dash_warn() {
printf "\e[33m[dash]\e[0m %s\n" "$1" >&2
dash_log "WARN" "$1"
}
dash_error() {
printf "\e[31m[dash]\e[0m %s\n" "$1" >&2
dash_log "ERROR" "$1"
}
dash_success() {
printf "\e[32m[dash]\e[0m %s\n" "$1"
dash_log "SUCCESS" "$1"
}
# Check if command exists
dash_has() {
command -v "$1" &>/dev/null
}
# Load file if it exists
dash_load() {
local file="$1"
if [[ -f "$file" ]]; then
source "$file"
dash_log "DEBUG" "Loaded: $file"
return 0
else
dash_log "DEBUG" "Skipped (not found): $file"
return 1
fi
}
#------------------------------------------------------------------------------
# Initialize
#------------------------------------------------------------------------------
# Create cache directory
mkdir -p "${DASH_HOME}/cache"
# Start loading
dash_log "INFO" "Loading dash v${DASH_VERSION}"
#------------------------------------------------------------------------------
# 1. Load Environment Variables
#------------------------------------------------------------------------------
dash_load "${DASH_HOME}/config/env"
#------------------------------------------------------------------------------
# 2. Load Core Functions
#------------------------------------------------------------------------------
dash_load "${DASH_HOME}/functions/core.sh"
#------------------------------------------------------------------------------
# 3. Initialize ble.sh (BEFORE other tools for proper integration)
#------------------------------------------------------------------------------
# ble.sh must be loaded with --attach=none at the start
if [[ $- == *i* ]] && [[ -z "${DISABLE_BLE}" ]] && [[ -f "${DASH_HOME}/lib/ble.sh/out/ble.sh" ]]; then
source "${DASH_HOME}/lib/ble.sh/out/ble.sh" --attach=none
dash_log "INFO" "ble.sh initialized (pre-attach)"
# Set blesh-contrib path if available
if [[ -d "${DASH_HOME}/lib/blesh-contrib" ]]; then
export BLESH_CONTRIB="${DASH_HOME}/lib/blesh-contrib"
dash_log "INFO" "blesh-contrib path set"
fi
elif [[ -n "${DISABLE_BLE}" ]]; then
dash_log "INFO" "ble.sh disabled by DISABLE_BLE flag"
elif [[ $- == *i* ]]; then
dash_warn "ble.sh not found - enhanced line editing disabled"
fi
#------------------------------------------------------------------------------
# 4. Load bash-preexec (for command hooks)
#------------------------------------------------------------------------------
if [[ -f "${DASH_HOME}/lib/bash-preexec/bash-preexec.sh" ]]; then
source "${DASH_HOME}/lib/bash-preexec/bash-preexec.sh"
dash_log "INFO" "bash-preexec loaded"
fi
#------------------------------------------------------------------------------
# 5. Load Aliases
#------------------------------------------------------------------------------
dash_load "${DASH_HOME}/config/bash_aliases"
#------------------------------------------------------------------------------
# 6. Load Tool Integrations
#------------------------------------------------------------------------------
dash_load "${DASH_HOME}/config/integrations.sh"
#------------------------------------------------------------------------------
# 7. Load Custom Completions
#------------------------------------------------------------------------------
dash_load "${DASH_HOME}/completion/custom.sh"
#------------------------------------------------------------------------------
# 8. Load Command Hooks
#------------------------------------------------------------------------------
dash_load "${DASH_HOME}/config/hooks.sh"
#------------------------------------------------------------------------------
# 9. Load ble.sh config and attach (MUST BE LAST)
#------------------------------------------------------------------------------
if [[ ${BLE_VERSION-} ]]; then
# Load blerc configuration
dash_load "${DASH_HOME}/config/blerc"
# Import integrations only if interactive
if [[ $- == *i* ]]; then
# Load blesh-contrib integrations if available
if [[ -d "${BLESH_CONTRIB}" ]]; then
ble-import -d integration 2>/dev/null && dash_log "INFO" "blesh-contrib integrations loaded"
fi
# Load standard integrations
ble-import -f integration/fzf-completion 2>/dev/null && dash_log "DEBUG" "fzf-completion loaded"
ble-import -f integration/fzf-key-bindings 2>/dev/null && dash_log "DEBUG" "fzf-key-bindings loaded"
ble-import -f integration/bash-preexec 2>/dev/null && dash_log "DEBUG" "bash-preexec integration loaded"
fi
# Attach ble.sh (this activates the enhanced line editing)
ble-attach
dash_log "INFO" "ble.sh attached"
fi
#------------------------------------------------------------------------------
# Performance Report (Optional)
#------------------------------------------------------------------------------
if [[ -n "${DASH_DEBUG}" ]]; then
DASH_LOAD_END=$(date +%s%3N)
DASH_LOAD_TIME=$((DASH_LOAD_END - DASH_LOAD_START))
dash_info "Loaded in ${DASH_LOAD_TIME}ms"
fi
#------------------------------------------------------------------------------
# Mark as loaded
#------------------------------------------------------------------------------
export DASH_LOADED=1
dash_log "INFO" "dash framework loaded successfully"
# Add dash bin to PATH
export PATH="${DASH_HOME}/bin:${PATH}"
# Welcome message (only on first interactive shell)
if [[ $- == *i* ]] && [[ ! -f "${DASH_HOME}/cache/.welcomed" ]]; then
printf "\e[1;36m╔════════════════════════════════════════╗\e[0m\n"
printf "\e[1;36m║\e[0m Welcome to \e[1;35mdash\e[0m v${DASH_VERSION} \e[1;36m║\e[0m\n"
printf "\e[1;36m║\e[0m Enhanced Bash Environment \e[1;36m║\e[0m\n"
printf "\e[1;36m║\e[0m \e[1;36m║\e[0m\n"
printf "\e[1;36m║\e[0m Run: \e[33mdash help\e[0m for commands \e[1;36m║\e[0m\n"
printf "\e[1;36m║\e[0m Run: \e[33mdash-check\e[0m to verify setup \e[1;36m║\e[0m\n"
printf "\e[1;36m║\e[0m Run: \e[33mdash-doctor\e[0m for diagnostics \e[1;36m║\e[0m\n"
printf "\e[1;36m╚════════════════════════════════════════╝\e[0m\n"
touch "${DASH_HOME}/cache/.welcomed"
fi