Speed up loading by merging

This commit is contained in:
斟酌 鵬兄 2022-08-12 00:00:30 +08:00
parent 0f834521dd
commit f271e1fb55

View File

@ -26,6 +26,8 @@ fi
mkdir -p "$RBASH_SOURCES" mkdir -p "$RBASH_SOURCES"
RBASH_MERGED="$RBASH_SOURCES/merged"
# don't put duplicate lines or lines starting with space in the history. # don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options # See bash(1) for more options
HISTCONTROL=ignoreboth HISTCONTROL=ignoreboth
@ -109,12 +111,32 @@ function rbash_cache {
echo -n "$CACHE_FILE" echo -n "$CACHE_FILE"
} }
# User specific aliases and functions _RBASH_LOADED=
function rbash_load { function rbash_load {
local f path local f path
if [ -z "$_RBASH_UPGRADE" ]; then
if [ -n "$_RBASH_LOADED" ]; then
return 0
fi
if [ -f "$RBASH_MERGED" ]; then
source $RBASH_MERGED
if [ $? -eq 0 ]; then
_RBASH_LOADED=1
return 0
fi
rm "$RBASH_MERGED"
fi
fi
echo "Load: $1" echo "Load: $1"
f=`rbash_cache "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/$1"` f=`rbash_cache "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/$1"`
source "$f" source "$f"
echo "echo \"Load: $1\"" >> "$RBASH_MERGED"
cat "$f" >> "$RBASH_SOURCES/merged"
chmod 700 "$RBASH_MERGED"
} }
function rbash-upgrade { function rbash-upgrade {
@ -151,7 +173,9 @@ function rbash-upgrade {
rm -r "$RBASH_SOURCES" rm -r "$RBASH_SOURCES"
fi fi
_RBASH_UPGRADE=1
source $__SCRIPT source $__SCRIPT
unset _RBASH_UPGRADE
} }
function rbash-run { function rbash-run {
@ -219,7 +243,7 @@ function r2ensource {
echo "Enabling $_id" echo "Enabling $_id"
done done
sort $_tmp > "$RBASH_CONFIG" sort $_tmp > "$RBASH_CONFIG"
rm $_tmp rm $_tmp "$RBASH_MERGED"
} }
function r2dissource { function r2dissource {
@ -246,7 +270,7 @@ function r2dissource {
_dis=$( mktemp ) _dis=$( mktemp )
sh -c "grep -v $_opts \"$RBASH_CONFIG\"" > $_dis sh -c "grep -v $_opts \"$RBASH_CONFIG\"" > $_dis
sort $_dis > $RBASH_CONFIG sort $_dis > $RBASH_CONFIG
rm $_dis rm $_dis "$RBASH_MERGED"
} }
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ ' export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '