Simplify PS1 logics

This commit is contained in:
斟酌 鵬兄 2022-08-15 21:21:35 +08:00
parent d15e69b944
commit 3c63b5d2d6

View File

@ -14,15 +14,23 @@ RBASH_ENV="$RBASH_HOME/env"
RBASH_REMOTE="https://git.k8s.astropenguin.net"
RBASH_REPO="penguin/utils"
RBASH_PATH="bash"
RBASH_MERGED="$RBASH_SOURCES/merged"
RHOSTNAME="<HOSTNAME>"
RDOMAIN="<DOMAIN>"
RCOLOR="<RCOLOR>"
if [ $RHOSTNAME == "<HOSTNAME"">" ]; then
RHOSTNAME=$( hostname -s )
RDOMAIN="@"$( hostname -d )
RCOLOR=$(( $RANDOM * 6 / 32767 + 1 ))
fi
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# The merged sources
RBASH_MERGED="$RBASH_SOURCES/merged"
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
@ -156,28 +164,24 @@ function rbash-reload {
function rbash-upgrade {
echo "Updating $__SCRIPT"
local TMPFILE
local TMPFILE _P_HOSTNAME _P_DOMAIN _P_COLOR
TMPFILE=$( mktemp )
__download "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/rbashrc" > $TMPFILE
if [ -z "$1" ]; then
MC_NAME="<MACHINE_NAME>"
MCC_NAME="<MACHINE_COLORED_NAME>"
else
MC_NAME=$1
MCC_NAME=$2
if [ -n "$1" ]; then
RHOSTNAME=$1
RDOMAIN=$2
fi
PMC_NAME=$( echo "#_MACHINE_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
PMCC_NAME=$( echo "#_MACHINE_COLORED_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
COLOR_CODE_TOK=$( echo "#_COLOR_CODE_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
COLOR_CODE=$(( $RANDOM * 6 / 32767 + 1 ))
_P_HOSTNAME="<HOSTNAME"">"
_P_DOMAIN="<DOMAIN"">"
_P_COLOR_CODE="<RCOLOR"">"
sed -i \
-e "s/$PMC_NAME/$MC_NAME/g" \
-e "s/$PMCC_NAME/$MCC_NAME/g" \
-e "s/$COLOR_CODE_TOK/$COLOR_CODE/g" \
-e "s/$_P_HOSTNAME/$RHOSTNAME/g" \
-e "s/$_P_DOMAIN/$RDOMAIN/g" \
-e "s/$_P_COLOR_CODE/$RCOLOR/g" \
$TMPFILE
mv $TMPFILE $__SCRIPT
@ -285,7 +289,7 @@ function r2dissource {
rm -r "$_dis" "$RBASH_SOURCES"
}
export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
export PS1="This is ${RHOSTNAME}\e[1;3${RCOLOR}m${RDOMAIN}\e[0m: \w\n\$ "
export EDITOR=vim
# Source for custom bash env, allows overriding
@ -305,5 +309,5 @@ ___DEFAULT___
chmod 600 "$RBASH_CONFIG"
fi
source "$RBASH_CONFIG"
ource "$RBASH_CONFIG"
unset _RBASH_MERGE_START