Simplify PS1 logics
This commit is contained in:
parent
d15e69b944
commit
3c63b5d2d6
42
bash/rbashrc
42
bash/rbashrc
@ -14,15 +14,23 @@ RBASH_ENV="$RBASH_HOME/env"
|
|||||||
RBASH_REMOTE="https://git.k8s.astropenguin.net"
|
RBASH_REMOTE="https://git.k8s.astropenguin.net"
|
||||||
RBASH_REPO="penguin/utils"
|
RBASH_REPO="penguin/utils"
|
||||||
RBASH_PATH="bash"
|
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
|
# Source global definitions
|
||||||
if [ -f /etc/bashrc ]; then
|
if [ -f /etc/bashrc ]; then
|
||||||
. /etc/bashrc
|
. /etc/bashrc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# The merged 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
|
||||||
@ -156,28 +164,24 @@ function rbash-reload {
|
|||||||
function rbash-upgrade {
|
function rbash-upgrade {
|
||||||
echo "Updating $__SCRIPT"
|
echo "Updating $__SCRIPT"
|
||||||
|
|
||||||
local TMPFILE
|
local TMPFILE _P_HOSTNAME _P_DOMAIN _P_COLOR
|
||||||
|
|
||||||
TMPFILE=$( mktemp )
|
TMPFILE=$( mktemp )
|
||||||
__download "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/rbashrc" > $TMPFILE
|
__download "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/rbashrc" > $TMPFILE
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
MC_NAME="<MACHINE_NAME>"
|
RHOSTNAME=$1
|
||||||
MCC_NAME="<MACHINE_COLORED_NAME>"
|
RDOMAIN=$2
|
||||||
else
|
|
||||||
MC_NAME=$1
|
|
||||||
MCC_NAME=$2
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PMC_NAME=$( echo "#_MACHINE_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
_P_HOSTNAME="<HOSTNAME"">"
|
||||||
PMCC_NAME=$( echo "#_MACHINE_COLORED_NAME_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
_P_DOMAIN="<DOMAIN"">"
|
||||||
COLOR_CODE_TOK=$( echo "#_COLOR_CODE_#" | sed -e "s/#_/</g" -e "s/_#/>/g" )
|
_P_COLOR_CODE="<RCOLOR"">"
|
||||||
COLOR_CODE=$(( $RANDOM * 6 / 32767 + 1 ))
|
|
||||||
|
|
||||||
sed -i \
|
sed -i \
|
||||||
-e "s/$PMC_NAME/$MC_NAME/g" \
|
-e "s/$_P_HOSTNAME/$RHOSTNAME/g" \
|
||||||
-e "s/$PMCC_NAME/$MCC_NAME/g" \
|
-e "s/$_P_DOMAIN/$RDOMAIN/g" \
|
||||||
-e "s/$COLOR_CODE_TOK/$COLOR_CODE/g" \
|
-e "s/$_P_COLOR_CODE/$RCOLOR/g" \
|
||||||
$TMPFILE
|
$TMPFILE
|
||||||
|
|
||||||
mv $TMPFILE $__SCRIPT
|
mv $TMPFILE $__SCRIPT
|
||||||
@ -285,7 +289,7 @@ function r2dissource {
|
|||||||
rm -r "$_dis" "$RBASH_SOURCES"
|
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
|
export EDITOR=vim
|
||||||
|
|
||||||
# Source for custom bash env, allows overriding
|
# Source for custom bash env, allows overriding
|
||||||
@ -305,5 +309,5 @@ ___DEFAULT___
|
|||||||
chmod 600 "$RBASH_CONFIG"
|
chmod 600 "$RBASH_CONFIG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source "$RBASH_CONFIG"
|
ource "$RBASH_CONFIG"
|
||||||
unset _RBASH_MERGE_START
|
unset _RBASH_MERGE_START
|
||||||
|
Loading…
Reference in New Issue
Block a user