38 lines
1.5 KiB
Bash
38 lines
1.5 KiB
Bash
#!/bin/bash
|
|
function set_bash_prompt () {
|
|
local LAST_EXIT_STATUS=$?
|
|
local EXIT_STATUS=""
|
|
local GIT_BRANCH=""
|
|
local PYTHON_ENV=""
|
|
local K8S_CURRENT_CONTEXT=""
|
|
|
|
local COLOR_OFF='\033[0m'
|
|
local COLOR_DIVIDER="\033[0;32m"
|
|
local COLOR_USERNAME="\[\e[34;1m\]"
|
|
local COLOR_USERHOSTAT="\[\e[34;1m\]"
|
|
local COLOR_HOSTNAME="\[\e[34;1m\]"
|
|
local COLOR_GITBRANCH="\[\e[33;1m\]"
|
|
local COLOR_VENV="\033[0;36m"
|
|
local COLOR_PATH="\033[0;37m"
|
|
local COLOR_EXIT_STATUS="[\033[1;37m\033[41m"
|
|
local COLOR_KUBERNETES="\033[1;37m\033[44m"
|
|
|
|
local CURRENT_CONTEXT=""
|
|
|
|
[[ $LAST_EXIT_STATUS != 0 ]] && EXIT_STATUS="${COLOR_DIVIDER}${COLOR_EXIT_STATUS}${LAST_EXIT_STATUS}${COLOR_DIVIDER}]"
|
|
[[ $(type -t __git_ps1) == function ]] && GIT_BRANCH="${COLOR_GITBRANCH}$(__git_ps1)${COLOR_DIVIDER}"
|
|
[[ -n "$VIRTUAL_ENV" ]] && PYTHON_ENV="${COLOR_DIVIDER}(${COLOR_VENV}${VIRTUAL_ENV##*/}${COLOR_DIVIDER})"
|
|
if [[ $(type kubectl) ]]; then
|
|
CURRENT_CONTEXT="$(kubectl config current-context)"
|
|
if [[ "$CURRENT_CONTEXT" != "default" ]];then
|
|
K8S_CURRENT_CONTEXT="${COLOR_DIVIDER}[${COLOR_KUBERNETES}${CURRENT_CONTEXT}${COLOR_DIVIDER}]"
|
|
fi
|
|
fi
|
|
|
|
PS1="\n${COLOR_DIVIDER}┌──(${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER})─[${COLOR_PATH}\w${COLOR_DIVIDER}]${EXIT_STATUS}${PYTHON_ENV}${K8S_CURRENT_CONTEXT}${GIT_BRANCH}"
|
|
PS1="${PS1}\n${COLOR_DIVIDER}└─\$${COLOR_OFF} "
|
|
}
|
|
|
|
|
|
export PROMPT_COMMAND=set_bash_prompt
|