mirror of https://github.com/nirenjan/dotfiles.git
Split prompt into two lines
Prior to this change, we were setting PS1 manually and having to muck with the \[, \] pairs for terminal escapes was proving to be too much. Instead, we moved to using a function used in PROMPT_COMMAND which displays the user, hostname and directory on one line, followed by the actual prompt line which displays the git status.master
parent
46214fd02f
commit
a35fd2cea0
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue