2021-11-11 15:27:24 +00:00
|
|
|
#!/bin/bash
|
2021-11-12 11:54:38 +00:00
|
|
|
function bash_ps1 () {
|
2021-11-11 15:27:24 +00:00
|
|
|
local LAST_EXIT_STATUS=$?
|
|
|
|
local EXIT_STATUS=""
|
2021-11-12 10:36:09 +00:00
|
|
|
local GIT_BRANCH=""
|
|
|
|
local PYTHON_ENV=""
|
|
|
|
local K8S_CURRENT_CONTEXT=""
|
2021-11-12 11:21:38 +00:00
|
|
|
local DOTF=""
|
2021-11-12 11:47:28 +00:00
|
|
|
local TODO=""
|
2021-11-12 11:21:38 +00:00
|
|
|
local STATUS=""
|
2021-11-11 15:27:24 +00:00
|
|
|
|
2021-11-12 12:44:34 +00:00
|
|
|
local COLOR_OFF='\[\033[0m\]'
|
|
|
|
local COLOR_DIVIDER='\[\033[0;32m\]'
|
2021-11-12 12:03:57 +00:00
|
|
|
local COLOR_USERNAME='\[\e[34;1m\]'
|
|
|
|
local COLOR_USERHOSTAT='\[\e[34;1m\]'
|
|
|
|
local COLOR_HOSTNAME='\[\e[34;1m\]'
|
|
|
|
local COLOR_GITBRANCH='\[\e[33;1m\]'
|
2021-11-12 12:44:34 +00:00
|
|
|
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 COLOR_TODO='\[\033[1;30m\]\[\033[43m\]'
|
|
|
|
local COLOR_DOTF='\[\033[1;37m\]\[\033[45m\]'
|
2021-11-11 15:27:24 +00:00
|
|
|
|
2021-11-12 10:36:09 +00:00
|
|
|
local CURRENT_CONTEXT=""
|
2021-11-11 15:27:24 +00:00
|
|
|
|
2021-11-13 14:42:10 +00:00
|
|
|
export GIT_PS1_SHOWCOLORHINTS=1
|
|
|
|
export GIT_PS1_SHOWDIRTYSTATE=1
|
|
|
|
export GIT_PS1_SHOWUNTRACKEDFILES=1
|
|
|
|
|
2021-11-14 10:50:33 +00:00
|
|
|
[[ $LAST_EXIT_STATUS != 0 ]] && EXIT_STATUS="${COLOR_DIVIDER}[${COLOR_EXIT_STATUS}${LAST_EXIT_STATUS}${COLOR_DIVIDER}]"
|
2021-11-12 10:36:09 +00:00
|
|
|
[[ $(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
|
2021-11-11 15:27:24 +00:00
|
|
|
fi
|
2021-11-12 10:36:09 +00:00
|
|
|
|
2021-11-12 12:46:32 +00:00
|
|
|
if [[ $(type -t status_dotfiles) == function ]];then
|
|
|
|
if [[ $(status_dotfiles check_error) == YES ]];then
|
2021-11-12 11:21:38 +00:00
|
|
|
DOTF="${COLOR_DOTF}E"
|
2021-11-12 12:46:32 +00:00
|
|
|
elif [[ $(status_dotfiles check_status) ]];then
|
2021-11-12 11:21:38 +00:00
|
|
|
DOTF="${COLOR_DOTF}."
|
2021-11-12 12:46:32 +00:00
|
|
|
elif [[ $(status_dotfiles check_push) ]];then
|
2021-11-12 11:21:38 +00:00
|
|
|
DOTF="${COLOR_DOTF}p"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-11-12 11:47:28 +00:00
|
|
|
if [[ $(type -t todo_status) == function ]] && [[ "$(todo_status)" == "YES" ]];then
|
|
|
|
TODO="${COLOR_TODO}T"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $DOTF ]] || [[ -n $TODO ]];then
|
|
|
|
STATUS="${COLOR_DIVIDER}[${DOTF}${TODO}${COLOR_DIVIDER}]"
|
2021-11-12 11:21:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
PS1="\n${COLOR_DIVIDER}┌──(${COLOR_USERNAME}\u${COLOR_USERHOSTAT}@${COLOR_HOSTNAME}\h${COLOR_DIVIDER})─[${COLOR_PATH}\w${COLOR_DIVIDER}]${EXIT_STATUS}${STATUS}${PYTHON_ENV}${K8S_CURRENT_CONTEXT}${GIT_BRANCH}"
|
2021-11-12 10:36:09 +00:00
|
|
|
PS1="${PS1}\n${COLOR_DIVIDER}└─\$${COLOR_OFF} "
|
2021-11-11 15:27:24 +00:00
|
|
|
}
|
|
|
|
|
2021-11-12 10:36:09 +00:00
|
|
|
|
2021-11-12 11:54:38 +00:00
|
|
|
export PROMPT_COMMAND=bash_ps1
|