From 247bc00ccf4e29d87ff1c50f3ce6d03ccdacdc0a Mon Sep 17 00:00:00 2001 From: a-Sansara Date: Thu, 28 Feb 2019 10:08:22 +0100 Subject: [PATCH] initial commit --- src/.bash_ps1 | 45 +++++++++++++++++++++++ src/ps1 | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 src/.bash_ps1 create mode 100755 src/ps1 diff --git a/src/.bash_ps1 b/src/.bash_ps1 new file mode 100644 index 0000000..be34ca7 --- /dev/null +++ b/src/.bash_ps1 @@ -0,0 +1,45 @@ +#!/bin/bash +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# @author a-Sansara - https://git.pluie.org/meta-tech/bes-ps1 +# @app bes-ps1 +# @license GNU GPL v3 +# @date 2017-10-23 23:30:54 CET +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +if [ -f /usr/share/bes/ps1 ]; then + + function bes.ps1.init() { + . /usr/share/bes/ps1 + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # ~~ FLAG 0|1 (disable|enable) + local BES_PS1_ACTIVE_DATE=1 + local BES_PS1_ACTIVE_CTX=1 + local BES_PS1_ACTIVE_NAME=1 + local BES_PS1_ACTIVE_PATH=1 + local BES_PS1_ACTIVE_GIT=1 + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # ~~ OVERLOAD DEFAULT COLORS (CTX is predifined depending on related ENV) + local BES_PS1_COLOR_DATE="255 215 15" + local BES_PS1_COLOR_USER="255 232 160" + local BES_PS1_COLOR_ROOT="237 164 115" + local BES_PS1_COLOR_PATH=" 74 160 198" + local BES_PS1_COLOR_HOST="255 255 255" + local BES_PS1_COLOR_GIT="237 164 115" + local BES_PS1_COLOR_SYMBOL="255 195 135" + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # -- INSTANCE COLORS - use for example in dockerfile + #~ export BES_PS1_BG=154 99 170 + #~ export BES_PS1_FG=255 255 255 + # -- INSTANCE ENVIRONMENT (LOCAL|DEV|INT|PROD) + #~ export BES_PS1_CTX=DEV + # -- INSTANCE NAME + #~ export BES_PS1_NAME=home + # -- INSTANCE TYPE (VM|DOCKER|whatyouwant) + #~ export BES_PS1_TYPE=DOCKER + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + bes.ps1 + } + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + bes.ps1.init +fi diff --git a/src/ps1 b/src/ps1 new file mode 100755 index 0000000..8dfca97 --- /dev/null +++ b/src/ps1 @@ -0,0 +1,99 @@ +#!/bin/bash +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# @author a-Sansara - https://git.pluie.org/meta-tech/bes-color +# @app bes-color +# @license GNU GPL v3 +# @date 2017-10-23 23:30:54 CET +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function ps1.fg() +{ + local -n var=$1 + var="\033[1;38;2;$2;$3;$4m" +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function ps1.bg() +{ + local -n var=$1 + var="\033[1;48;2;$2;$3;$4m" +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function ps1.env () { + local -n var=${2:-shenv} + local v=ctx$1 + local ctxPROD="174 8 49" + local ctxINT="218 84 0" + local ctxDEV="218 159 0" + local ctxLOCAL="122 122 122" + if [ -z "${!v}" ]; then + v=ctxLOCAL + BES_PS1_CTX=LOCAL + fi + var=${!v} +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function ps1.git.branch() { + git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function ps1.space() +{ + if [ "${ps1: -1}" != " " ]; then + if [ "$ps1" != "" ]; then + ps1="$ps1 "; + fi + fi +} +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function bes.ps1() { + local Cdate Cctx Cname Cpath Cuser Chost Csymbol Coff shenvtype ps1 + Coff="\\033[m" + if [ -z "$BES_PS1_BG" ]; then BES_PS1_BG="154 99 170"; fi + if [ -z "$BES_PS1_FG" ]; then BES_PS1_FG="255 255 255"; fi + if [ -z "$BES_PS1_NAME" ]; then BES_PS1_NAME="home"; fi + ps1.env "$BES_PS1_CTX" shenv + if [ -z "$BES_PS1_TYPE" ]; then + shenvtype=" $BES_PS1_CTX " + else + echo "mota" + shenvtype=" $BES_PS1_TYPE " + fi + + ps1.fg "Cdate" $BES_PS1_COLOR_DATE + ps1.bg "Cnamebg" $BES_PS1_BG + ps1.fg "Cnamefg" $BES_PS1_FG + ps1.bg "Cctx" $shenv + ps1.fg "Cctxfg" 255 255 255 + ps1.fg "Cpath" $BES_PS1_COLOR_PATH + ps1.fg "Chost" 255 255 255 + ps1.fg "Csymbol" $BES_PS1_COLOR_SYMBOL + if [ "$USER" != "root" ]; then + ps1.fg "Cuser" $BES_PS1_COLOR_USER + else + ps1.fg "Cuser" $BES_PS1_COLOR_ROOT + fi + ps1.fg "Cgit" $BES_PS1_COLOR_GIT + + ps1="" + if [ "$BES_PS1_ACTIVE_DATE" = "1" ]; then + ps1="$ps1\[${Cdate}\]\t " + fi + if [ "$BES_PS1_ACTIVE_CTX" = "1" ]; then + ps1="$ps1\[${Cctxfg}\]\[${Cctx}\]${shenvtype}\[${Coff}\]" + fi + if [ "$BES_PS1_ACTIVE_NAME" = "1" ]; then + ps1="$ps1\[${Cnamebg}\] \[${Cnamefg}\]${BES_PS1_NAME} \[${Coff}\]" + fi + ps1.space + ps1="$ps1\[${Cuser}\]\u\[${Chost}\]@\h" + if [ "$BES_PS1_ACTIVE_PATH" = "1" ]; then + ps1.space + ps1="$ps1\[${Cpath}\]\w" + fi + if [ "$BES_PS1_ACTIVE_GIT" = "1" ]; then + ps1="$ps1\[${Cgit}\]\$(ps1.git.branch)" + fi + ps1="$ps1 \[${Csymbol}\]\$ \[${Coff}\]" + export PS1="$ps1" +}