Skip to content

Instantly share code, notes, and snippets.

@kentquirk
Created August 9, 2018 02:10
Show Gist options
  • Save kentquirk/4f9dd3670d7960bfe51b1d40cd2dd221 to your computer and use it in GitHub Desktop.
Save kentquirk/4f9dd3670d7960bfe51b1d40cd2dd221 to your computer and use it in GitHub Desktop.
kent's color prompt
#################################################################
# Here's a bunch of stuff to do prompts that are sensitive to git and svn
# sets the title of the iterm2 window
title()
{
TITLE=$*;
export PROMPT_COMMAND='echo -ne "\033]0;$TITLE\007"'
}
# sets the title of iterm2 to the current directory tail
titledir()
{
export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"'
}
# dark color component
dcc()
{
jot -nr 1 20 120
}
# light color component
lcc()
{
jot -nr 1 130 255
}
rndDarkBg()
{
echo '\e[48;2;$(dcc);$(dcc);$(dcc)m'
}
rndLightFg()
{
echo '\e[38;2;$(lcc);$(lcc);$(lcc)m'
}
titledir
WHT='\e[22;37m'
TEAL='\e[22;36m'
BLK='\e[22;30m'
RED='\e[22;31m'
GRN='\e[22;32m'
YEL='\e[22;33m'
BLU='\e[22;34m'
MAG='\e[22;35m'
CYN='\e[22;36m'
BRED='\e[1;31m'
BGRN='\e[1;32m'
BYEL='\e[1;33m'
BBLU='\e[1;34m'
BMAG='\e[1;35m'
BCYN='\e[1;36m'
BWHT='\e[1;37m'
BBLK='\e[1;30m'
BGBLK='\e[40m'
BGRED='\e[41m'
BGGRN='\e[42m'
BGYEL='\e[43m'
BGBLU='\e[44m'
BGMAG='\e[45m'
BGCYN='\e[46m'
BGWHT='\e[47m'
KILLCOLOR='\e[0m'
CLEAREOL='\e[K'
TIME='\@'
USER='\u'
HOST='\h'
WORKINGDIR='\w'
CLR_FRAME=$WHT
CLR_DIR=$BRED
CLR_GIT=$BYEL
CLR_TIME=$BWHT
CLR_BG=$BGBLU
CLR_VENV=$GRN
parse_git_branch() {
git symbolic-ref --short HEAD 2> /dev/null
}
parse_svn_revision() {
svn info 2>/dev/null | grep "Revision: "| cut -d ' ' -f 2
}
get_revision() {
svn info >/dev/null 2>&1 && parse_svn_revision || parse_git_branch
}
get_venv() {
if [ ! -z $VIRTUAL_ENV ]; then
echo " ($(basename $VIRTUAL_ENV))"
fi
}
# Only do a color prompt if we actually want color
case "$TERM" in
xterm-256color)
PS1="$(rndDarkBg) $CLR_FRAME[$(rndLightFg)$TIME$CLR_FRAME][$(rndLightFg)$WORKINGDIR$(rndLightFg)\$(get_venv)$CLR_FRAME][$(rndLightFg)\$(get_revision)$CLR_FRAME] $CLEAREOL$KILLCOLOR\n\$ "
;;
*)
PS1="[ $TIME ][ $WORKINGDIR \$(get_venv) ][ \$(get_revision) ] \n\$ "
;;
esac
#################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment