diff --git a/bash/bashrc.d/git_prompt.bash b/bash/bashrc.d/git_prompt.bash index 2024cc1..99a7e09 100644 --- a/bash/bashrc.d/git_prompt.bash +++ b/bash/bashrc.d/git_prompt.bash @@ -3,6 +3,7 @@ # Define the colors used by the prompt if [[ ! -z $TERM && "$TERM" != "dumb" ]] then + T_R=$(tput setaf 1) # Red T_B=$(tput setaf 4) # Blue T_G=$(tput setaf 2) # Green T_Y=$(tput setaf 3) # Yellow @@ -10,17 +11,51 @@ then else # We've probably been invoked by an SSH command, there's no terminal # to deal with. Don't bother coloring the prompt. + T_R='' T_B='' T_G='' T_Y='' T_S='' fi +# Define a default prompt string +export PS1='\$ ' + +# Define a default __git_ps1 in case we don't have git prompt functionality +__git_ps1() +{ + : +} + # Import the Git prompt shell functions. These can be found # @github:git/git/contrib/completion/git_prompt.sh if [ -f $HOME/.git_prompt.sh ]; then source $HOME/.git_prompt.sh - export PS1='\[$T_B\]\u@\h \[$T_S\][\[$T_G\]$(smartwd)$(__git_ps1 " \[$T_Y\](%s)")\[$T_S\]]\$ ' -else - export PS1='\[$T_B\]\u@\h \[$T_S\][\[$T_G\]$(smartwd)\[$T_S\]]\$ ' +fi + +# Prompt header function, prints user, hostname and current directory +prompt_header() +{ + local last_result="$?" + + echo + echo -ne "${T_Y}$(date '+%F %T')${T_S} " + echo -ne "${T_B}${USER}@${HOSTNAME} ${T_S}[${T_G}$(smartwd)${T_S}]" + if [[ $last_result != 0 ]] + then + echo -ne " ${T_R}!! ${last_result} !!${T_S} " + fi + echo + + # Configuration for __git_ps1 + GIT_PS1_SHOWCOLORHINTS=yes + GIT_PS1_SHOWDIRTYSTATE=yes + GIT_PS1_SHOWUNTRACKEDFILES=yes + GIT_PS1_SHOWUPSTREAM=verbose + __git_ps1 '' '\$ ' '(%s)' +} + +if [[ ! -z $TERM && "$TERM" != "dumb" ]] +then + export PROMPT_COMMAND='prompt_header' fi