commit d602f080645afc71bf61d9a264cd0ec42d4557b8
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2026-06-26T10:55:00Z |
| subject | Added back auto_reload |
commit d602f080645afc71bf61d9a264cd0ec42d4557b8
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2026-06-26T10:55:00Z
Added back auto_reload
---
bash/core/30_loader.bash | 67 +++++++++++++++++++++++-------------
bash/core/90_prompt.bash | 24 +++++++------
bash/rbashrc | 88 ++++++++++++++++++++++++++++++++++--------------
3 files changed, 119 insertions(+), 60 deletions(-)
diff --git a/bash/core/30_loader.bash b/bash/core/30_loader.bash
index 8c94a4f..3859090 100755
--- a/bash/core/30_loader.bash
+++ b/bash/core/30_loader.bash
@@ -1,21 +1,51 @@
+rbash-reload() {
+ _RBASH_LOADED=
+ _RBASH_MERGE_START=1
+
+ mkdir -p "$RBASH_CACHE_DIR"
+
+ rm -f "$RBASH_MERGED"
+ : > "$RBASH_MERGED" || {
+ echo "rbash: failed to write merged cache: $RBASH_MERGED" >&2
+ _RBASH_MERGE_START=
+ return 1
+ }
+
+ # shellcheck source=/dev/null
+ source "$RBASH_CONFIG"
+
+ _RBASH_MERGE_START=
+ _RBASH_LOADED=1
+}
+
+__rbash_autoload() {
+ if [ -n "${_RBASH_LOADED:-}" ]; then
+ return 0
+ fi
+
+ if [ -f "$RBASH_MERGED" ]; then
+ # shellcheck source=/dev/null
+ source "$RBASH_MERGED" && {
+ _RBASH_LOADED=1
+ return 0
+ }
+
+ echo "rbash: merged cache failed, rebuilding" >&2
+ rm -f "$RBASH_MERGED"
+ fi
+
+ rbash-reload
+}
+
rbash_load() {
local rel="$1"
local url file
+ # Normal startup should not individually fetch sources.
+ # It should source RBASH_MERGED via __rbash_autoload.
if [ -z "${_RBASH_MERGE_START:-}" ]; then
- if [ -n "$_RBASH_LOADED" ]; then
- return 0
- fi
-
- if [ -f "$RBASH_MERGED" ]; then
- # shellcheck source=/dev/null
- source "$RBASH_MERGED" && {
- _RBASH_LOADED=1
- return 0
- }
-
- rm -f "$RBASH_MERGED"
- fi
+ __rbash_autoload
+ return 0
fi
echo "Load: $rel"
@@ -41,17 +71,6 @@ rbash_load() {
chmod 700 "$RBASH_MERGED"
}
-rbash-reload() {
- _RBASH_LOADED=
- _RBASH_MERGE_START=1
- rm -f "$RBASH_MERGED"
-
- # shellcheck source=/dev/null
- source "$RBASH_CONFIG"
-
- _RBASH_MERGE_START=
-}
-
rbash-run() {
local rel="$1"
local file
diff --git a/bash/core/90_prompt.bash b/bash/core/90_prompt.bash
index cf103a6..e10be57 100755
--- a/bash/core/90_prompt.bash
+++ b/bash/core/90_prompt.bash
@@ -1,13 +1,15 @@
-_SHELLD="\$"
+__rbash_setup_prompt() {
+ local shelld="\$"
-case "$OSTYPE" in
- cygwin*)
- if net session >/dev/null 2>&1; then
- _SHELLD="#"
- fi
- ;;
-esac
+ case "$OSTYPE" in
+ cygwin*)
+ if net session >/dev/null 2>&1; then
+ shelld="#"
+ fi
+ ;;
+ esac
-export PS1="This is ${RHOSTNAME}\e[1;3${RCOLOR}m${RDOMAIN}\e[0m: \w\n$_SHELLD "
-export EDITOR="${EDITOR:-vim}"
-export PATH="$RBASH_BIN:$PATH"
\ No newline at end of file
+ export PS1="This is ${RHOSTNAME}\e[1;3${RCOLOR}m${RDOMAIN}\e[0m: \w\n$shelld "
+ export EDITOR="${EDITOR:-vim}"
+ export PATH="$RBASH_BIN:$PATH"
+}
diff --git a/bash/rbashrc b/bash/rbashrc
index 08d66bc..70619ce 100755
--- a/bash/rbashrc
+++ b/bash/rbashrc
@@ -180,24 +180,54 @@ _require_jq() {
# ---- rbash: bash/core/30_loader.bash ----
+rbash-reload() {
+ _RBASH_LOADED=
+ _RBASH_MERGE_START=1
+
+ mkdir -p "$RBASH_CACHE_DIR"
+
+ rm -f "$RBASH_MERGED"
+ : > "$RBASH_MERGED" || {
+ echo "rbash: failed to write merged cache: $RBASH_MERGED" >&2
+ _RBASH_MERGE_START=
+ return 1
+ }
+
+ # shellcheck source=/dev/null
+ source "$RBASH_CONFIG"
+
+ _RBASH_MERGE_START=
+ _RBASH_LOADED=1
+}
+
+__rbash_autoload() {
+ if [ -n "${_RBASH_LOADED:-}" ]; then
+ return 0
+ fi
+
+ if [ -f "$RBASH_MERGED" ]; then
+ # shellcheck source=/dev/null
+ source "$RBASH_MERGED" && {
+ _RBASH_LOADED=1
+ return 0
+ }
+
+ echo "rbash: merged cache failed, rebuilding" >&2
+ rm -f "$RBASH_MERGED"
+ fi
+
+ rbash-reload
+}
+
rbash_load() {
local rel="$1"
local url file
+ # Normal startup should not individually fetch sources.
+ # It should source RBASH_MERGED via __rbash_autoload.
if [ -z "${_RBASH_MERGE_START:-}" ]; then
- if [ -n "$_RBASH_LOADED" ]; then
- return 0
- fi
-
- if [ -f "$RBASH_MERGED" ]; then
- # shellcheck source=/dev/null
- source "$RBASH_MERGED" && {
- _RBASH_LOADED=1
- return 0
- }
-
- rm -f "$RBASH_MERGED"
- fi
+ __rbash_autoload
+ return 0
fi
echo "Load: $rel"
@@ -223,17 +253,6 @@ rbash_load() {
chmod 700 "$RBASH_MERGED"
}
-rbash-reload() {
- _RBASH_LOADED=
- _RBASH_MERGE_START=1
- rm -f "$RBASH_MERGED"
-
- # shellcheck source=/dev/null
- source "$RBASH_CONFIG"
-
- _RBASH_MERGE_START=
-}
-
rbash-run() {
local rel="$1"
local file
@@ -405,4 +424,23 @@ esac
export PS1="This is ${RHOSTNAME}\e[1;3${RCOLOR}m${RDOMAIN}\e[0m: \w\n$_SHELLD "
export EDITOR="${EDITOR:-vim}"
-export PATH="$RBASH_BIN:$PATH"
\ No newline at end of file
+export PATH="$RBASH_BIN:$PATH"
+
+# ---- rbash: bash/core/99_main.bash ----
+
+__rbash_main() {
+ mkdir -p "$RBASH_HOME" "$RBASH_CACHE_DIR" "$RBASH_BIN"
+
+ __rbash_init_config
+
+ if [ -f "$RBASH_ENV" ]; then
+ # shellcheck source=/dev/null
+ source "$RBASH_ENV"
+ fi
+
+ __rbash_autoload
+ __rbash_setup_prompt
+}
+
+__rbash_main
+unset -f __rbash_main
\ No newline at end of file