From b071bedf6dc022cfb685d480eacdaeb39a11f7af Mon Sep 17 00:00:00 2001 From: Jonas Forsberg Date: Sun, 14 Nov 2021 12:53:51 +0100 Subject: [PATCH] made colors overridable by setting variables --- .functions/ps1.sh | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/.functions/ps1.sh b/.functions/ps1.sh index 2fde50e..7564aa6 100644 --- a/.functions/ps1.sh +++ b/.functions/ps1.sh @@ -9,18 +9,17 @@ function bash_ps1 () { local TODO="" local STATUS="" - 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 COLOR_TODO='\[\033[1;30m\]\[\033[43m\]' - local COLOR_DOTF='\[\033[1;37m\]\[\033[45m\]' + local PS1_COLOR_OFF='\[\033[0m\]' + local PS1_COLOR_DIVIDER="${PS1_COLOR_DIVIDER:-\[\033[0;32m\]}" + local PS1_COLOR_USERNAME="${PS1_COLOR_USERNAME:-\[\e[34;1m\]}" + local PS1_COLOR_USERHOSTAT="${PS1_COLOR_USERHOSTAT:-\[\e[34;1m\]}" + local PS1_COLOR_HOSTNAME="${COLOR_HOSTNAME:-\[\e[34;1m\]}" + local PS1_COLOR_VENV="${PS1_COLOR_VENV:-\[\033[0;36m\]}" + local PS1_COLOR_PATH="${PS1_COLOR_PATH:-\[\033[0;37m\]}" + local PS1_COLOR_EXIT_STATUS="${PS1_COLOR_EXIT_STATUS:-\[\033[1;37m\]\[\033[41m\]}" + local PS1_COLOR_KUBERNETES="${PS1_COLOR_KUBERNETES:-\[\033[1;37m\]\[\033[44m\]}" + local PS1_COLOR_TODO="${PS1_COLOR_TODO:-\[\033[1;30m\]\[\033[43m\]}" + local PS1_COLOR_DOTF="${PS1_COLOR_DOTF:-\[\033[1;37m\]\[\033[45m\]}" local CURRENT_CONTEXT="" @@ -28,36 +27,36 @@ function bash_ps1 () { export GIT_PS1_SHOWDIRTYSTATE=1 export GIT_PS1_SHOWUNTRACKEDFILES=1 - [[ $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})" + [[ $LAST_EXIT_STATUS != 0 ]] && EXIT_STATUS="${PS1_COLOR_DIVIDER}[${PS1_COLOR_EXIT_STATUS}${LAST_EXIT_STATUS}${PS1_COLOR_DIVIDER}]" + [[ $(type -t __git_ps1) == function ]] && GIT_BRANCH="${PS1_COLOR_OFF}$(__git_ps1)" + [[ -n "$VIRTUAL_ENV" ]] && PYTHON_ENV="${PS1_COLOR_DIVIDER}(${PS1_COLOR_VENV}${VIRTUAL_ENV##*/}${PS1_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}]" + K8S_CURRENT_CONTEXT="${PS1_COLOR_DIVIDER}[${PS1_COLOR_KUBERNETES}${CURRENT_CONTEXT}${PS1_COLOR_DIVIDER}]" fi fi if [[ $(type -t status_dotfiles) == function ]];then if [[ $(status_dotfiles check_error) == YES ]];then - DOTF="${COLOR_DOTF}E" + DOTF="${PS1_COLOR_DOTF}E" elif [[ $(status_dotfiles check_status) ]];then - DOTF="${COLOR_DOTF}." + DOTF="${PS1_COLOR_DOTF}." elif [[ $(status_dotfiles check_push) ]];then - DOTF="${COLOR_DOTF}p" + DOTF="${PS1_COLOR_DOTF}p" fi fi if [[ $(type -t todo_status) == function ]] && [[ "$(todo_status)" == "YES" ]];then - TODO="${COLOR_TODO}T" + TODO="${PS1_COLOR_TODO}T" fi if [[ -n $DOTF ]] || [[ -n $TODO ]];then - STATUS="${COLOR_DIVIDER}[${DOTF}${TODO}${COLOR_DIVIDER}]" + STATUS="${PS1_COLOR_DIVIDER}[${DOTF}${TODO}${PS1_COLOR_DIVIDER}]" 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}" - PS1="${PS1}\n${COLOR_DIVIDER}└─\$${COLOR_OFF} " + PS1="\n${PS1_COLOR_DIVIDER}┌──(${PS1_COLOR_USERNAME}\u${PS1_COLOR_USERHOSTAT}@${PS1_COLOR_HOSTNAME}\h${PS1_COLOR_DIVIDER})─[${PS1_COLOR_PATH}\w${PS1_COLOR_DIVIDER}]${EXIT_STATUS}${STATUS}${PYTHON_ENV}${K8S_CURRENT_CONTEXT}${GIT_BRANCH}" + PS1="${PS1}\n${PS1_COLOR_DIVIDER}└─\$${PS1_COLOR_OFF} " }