dotfiles/home/.bash_prompt

51 lines
1 KiB
Bash

# defines __git_ps1
if [ -r ~/.bash_git ]; then
GIT_PS1_SHOWCOLORHINTS=1
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM="auto"
source ~/.bash_git
PROMPT_COMMAND=show_prompt
fi
# iTerm shell integration
if [ "${TERM_PROGRAM}" = "iTerm.app" ]; then
source ~/.homesick/repos/dotfiles/iterm2/iterm2_integration.sh
fi
function show_prompt {
local EXIT="$?"
# Time
local pre='\[\e[01;35m\]\t '
local post
# Check last return value
if [ $EXIT != 0 ]; then
pre+='\[\e[31m\]⬤'
else
pre+='\[\e[32m\]⬤'
fi
pre+=' \[\e[;37m\]\j \l '
# Test if root
if [ $EUID -ne 0 ]; then
pre+='\[\e[01;34m\]\u\[\e[01;33m\]@\[\e[01;36m\]\H'
post='\[\e[01;34m\]\w'
else
pre+='\[\e[31m\]\u\[\e[01;33m\]@\[\e[01;36m\]\H'
post='\[\e[01;33m\]\w'
fi
post+='\[\e[;37m\]\n \[\e[01;30m\]\# \[\e[31m\]\$ \[\e[00m\]'
if [[ $(git config --default true --get prompt.show) == "false" ]]; then
PS1="$pre $post"
else
__git_ps1 "$pre " "$post" '\[\e[01;30m\](%s\[\e[01;30m\]) '
fi
}