penguin/utils

my env utils

commit e54f73376c0b405028a0d5d9a3ee10a8255574e6

author斟酌 鵬兄 <tgckpg@gmail.com>
date2026-06-26T10:39:37Z
subjectRenamed RBASH_SOURCES to RBASH_CACHE_DIR
commit e54f73376c0b405028a0d5d9a3ee10a8255574e6
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2026-06-26T10:39:37Z

    Renamed RBASH_SOURCES to RBASH_CACHE_DIR
---
 bash/core/20_io.bash     | 14 +++++++++++++-
 bash/core/30_loader.bash |  2 +-
 bash/rbashrc             |  4 ++--
 bash/rbashrc.in          |  4 ++--
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/bash/core/20_io.bash b/bash/core/20_io.bash
index 6f19dc7..4d585dd 100755
--- a/bash/core/20_io.bash
+++ b/bash/core/20_io.bash
@@ -31,6 +31,16 @@ rbash_cache() {
   local url="$1"
   local key file
 
+  if [ -z "${RBASH_CACHE_DIR:-}" ]; then
+    echo "rbash: RBASH_CACHE_DIR is not set" >&2
+    return 1
+  fi
+
+  mkdir -p "$RBASH_CACHE_DIR" || {
+    echo "rbash: failed to create cache dir: $RBASH_CACHE_DIR" >&2
+    return 1
+  }
+
   if command -v md5sum >/dev/null 2>&1; then
     key="$(printf '%s' "$url" | md5sum | cut -d' ' -f1)"
   else
@@ -41,8 +51,10 @@ rbash_cache() {
 
   if [ ! -f "$file" ]; then
     rbash_download "$url" > "$file" || {
+      local rc=$?
       rm -f "$file"
-      return 1
+      echo "rbash: download failed: $url" >&2
+      return "$rc"
     }
     chmod 700 "$file"
   fi
diff --git a/bash/core/30_loader.bash b/bash/core/30_loader.bash
index 47ab551..8c94a4f 100755
--- a/bash/core/30_loader.bash
+++ b/bash/core/30_loader.bash
@@ -62,4 +62,4 @@ rbash-run() {
 
   file="$(rbash_cache "$(rbash_url "$rel")")" || return 1
   "$file" "$@"
-}
\ No newline at end of file
+}
diff --git a/bash/rbashrc b/bash/rbashrc
index 0b7e0a6..8ab284e 100755
--- a/bash/rbashrc
+++ b/bash/rbashrc
@@ -16,10 +16,10 @@ RBASH_REPO="${RBASH_REPO:-penguin/utils}"
 RBASH_REF="${RBASH_REF:-master}"
 RBASH_PATH="${RBASH_PATH:-bash}"
 
-RBASH_SOURCES="$RBASH_HOME/sources"
+RBASH_CACHE_DIR="$RBASH_HOME/sources"
 RBASH_CONFIG="$RBASH_HOME/config"
 RBASH_ENV="$RBASH_HOME/env"
-RBASH_MERGED="$RBASH_SOURCES/merged"
+RBASH_MERGED="$RBASH_CACHE_DIR/merged"
 RBASH_BIN="$RBASH_HOME/bin"
 
 RHOSTNAME="<HOSTNAME>"
diff --git a/bash/rbashrc.in b/bash/rbashrc.in
index 90ba762..694703a 100644
--- a/bash/rbashrc.in
+++ b/bash/rbashrc.in
@@ -16,10 +16,10 @@ RBASH_REPO="${RBASH_REPO:-penguin/utils}"
 RBASH_REF="${RBASH_REF:-master}"
 RBASH_PATH="${RBASH_PATH:-bash}"
 
-RBASH_SOURCES="$RBASH_HOME/sources"
+RBASH_CACHE_DIR="$RBASH_HOME/sources"
 RBASH_CONFIG="$RBASH_HOME/config"
 RBASH_ENV="$RBASH_HOME/env"
-RBASH_MERGED="$RBASH_SOURCES/merged"
+RBASH_MERGED="$RBASH_CACHE_DIR/merged"
 RBASH_BIN="$RBASH_HOME/bin"
 
 RHOSTNAME="<HOSTNAME>"