From a8c1d21d6ef296bdd5c80e9430ae89c46003200a Mon Sep 17 00:00:00 2001 From: Meutel Date: Mon, 1 May 2017 17:51:55 +0200 Subject: [PATCH] Colors, fix status --- _bashrc | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/_bashrc b/_bashrc index 7cc1044..b30ec62 100644 --- a/_bashrc +++ b/_bashrc @@ -2,7 +2,6 @@ [ -z "$PS1" ] && return ##### VARIABLES ##### - # don't put duplicate lines in the history. See bash(1) for more options export HISTCONTROL=ignoredups # ... and ignore same sucessive entries. @@ -29,12 +28,18 @@ if [ "$TERM" != "dumb" ]; then [ -x /usr/bin/dircolors ] && eval "`dircolors -b`" fi -GREEN='\[\033[0;32m\]' -GREENB='\[\033[1;32m\]' RED='\[\033[0;31m\]' REDB='\[\033[1;31m\]' +GREEN='\[\033[0;32m\]' +GREENB='\[\033[1;32m\]' +YELLOW='\[\033[0;33m\]' +YELLOWB='\[\033[1;33m\]' BLUE='\033[0;34m\]' BLUEB='\033[1;34m\]' +PURPLE='\[\033[0;35m\]' +PURPLEB='\[\033[1;35m\]' +CYAN='\[\033[0;36m\]' +CYANB='\[\033[1;36m\]' WHITE='\[\033[0;37m\]' WHITEB='\[\033[1;37m\]' RESET='\[\033[0;00m\]' @@ -84,15 +89,15 @@ fi export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock ##### PROMPT ##### - -# status indicator prompt_status() { - if [[ "$?" == "0" ]] + if [[ "$exitStatus" == "0" ]] then - echo -n "${GREENB}-" + echo -n $GREENB + echo -en '\xE2\x9a\x90' else - echo -n "${REDB}X" + echo -n $REDB + echo -en '\xE2\x9a\x91' fi } prompt_root() @@ -106,23 +111,33 @@ prompt_root() } prompt_remote() { - if [ -n "$SSH_CLIENT" ] + if [[ -n "$SSH_CLIENT" ]] then - echo -n "${REDB}>>" + echo -n "${RED}" else - echo -n "${GREENB}))" + echo -n "${GREEN}" fi } - +__ps1pre() +{ + export exitStatus=$? + echo -n "${WHITEB}(${WHITE}\u@$(prompt_remote)\h${WHITEB}) ${BLUEB}\w${RESET}" +} +__ps1post() +{ + echo -n "\n$(prompt_status) $(prompt_root)${RESET} " +} __ps1() { - ps1pre="$1" - ps1post="$2" - PS1="$ps1pre$ps1post" + exitStatus=$? + PS1="$(__ps1pre)$(__ps1post)" } -PS1pre='"$(prompt_remote) ${WHITEB}(${WHITE}\u@${GREEN}\h${WHITEB}) ${BLUEB}\w${RESET}"' -PS1post='"\n$(prompt_status)$(prompt_root)${RESET} "' -PROMPT_COMMAND="__ps1 $PS1pre $PS1post" +__ps1_git() +{ + exitStatus=$? + __git_ps1 "$(__ps1pre)" "$(__ps1post)" +} +PROMPT_COMMAND='__ps1' ##### GIT ##### @@ -141,6 +156,6 @@ if [ -e /usr/local/share/git-core/contrib/completion/git-prompt.sh ] || [ -e /us export GIT_PS1_SHOWUNTRACKEDFILES=1 export GIT_PS1_SHOWUPSTREAM="auto" export GIT_PS1_SHOWCOLORHINTS=1 - PROMPT_COMMAND="__git_ps1 $PS1pre $PS1post" + PROMPT_COMMAND='__ps1_git' fi