Skip to content

Instantly share code, notes, and snippets.

@42jerrykim
Last active December 7, 2018 02:10
Show Gist options
  • Save 42jerrykim/5fcf87ad9410555270205c3ca166cce6 to your computer and use it in GitHub Desktop.
Save 42jerrykim/5fcf87ad9410555270205c3ca166cce6 to your computer and use it in GitHub Desktop.
# dhfine colors
C_DEFAULT="\[\033[m\]"
C_WHITE="\[\033[1m\]"
C_BLACK="\[\033[30m\]"
C_RED="\[\033[31m\]"
C_GREEN="\[\033[32m\]"
C_YELLOW="\[\033[33m\]"
C_BLUE="\[\033[34m\]"
C_PURPLE="\[\033[35m\]"
C_CYAN="\[\033[36m\]"
C_LIGHTGRAY="\[\033[37m\]"
C_DARKGRAY="\[\033[1;30m\]"
C_LIGHTRED="\[\033[1;31m\]"
C_LIGHTGREEN="\[\033[1;32m\]"
C_LIGHTYELLOW="\[\033[1;33m\]"
C_LIGHTBLUE="\[\033[1;34m\]"
C_LIGHTPURPLE="\[\033[1;35m\]"
C_LIGHTCYAN="\[\033[1;36m\]"
C_BG_BLACK="\[\033[40m\]"
C_BG_RED="\[\033[41m\]"
C_BG_GREEN="\[\033[42m\]"
C_BG_YELLOW="\[\033[43m\]"
C_BG_BLUE="\[\033[44m\]"
C_BG_PURPLE="\[\033[45m\]"
C_BG_CYAN="\[\033[46m\]"
C_BG_LIGHTGRAY="\[\033[47m\]"
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_pink=`tput setaf 5`
c_sgr0=`tput sgr0`
parse_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
branchname="(git:"$(branch_color)$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')${c_sgr0}") "
elif hg prompt >/dev/null 2>&1
then
branchname="(hg:"$(branch_color)$(hg prompt "{branch}" 2>/dev/null)${c_sgr0}") "
else
return 0
fi
echo -e $branchname
}
branch_color ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
color=""
if git diff --quiet 2>/dev/null >&2
then
gitstatus=$(git status 2>/dev/null| tail -n1)
case "$gitstatus" in
"nothing to commit (working directory clean)" ) color=${c_green};;
* ) color=${c_pink};;
esac
else color=${c_red}
fi
elif hg prompt >/dev/null 2>&1
then
color=""
hgstatus=$(hg prompt {status} 2>/dev/null)
case "$hgstatus" in
"!" ) color=${c_red};;
"?" ) color=${c_pink};;
* ) color=${c_green};;
esac
else
return 0
fi
echo -ne $color
}
export PS1="$C_BG_CYAN$C_BLACK\u@\h$C_BG_BLACK$C_RED:\w\[${c_sgr0}\]"'$(parse_branch)'"$C_BG_BLACK$C_RED\n\$$C_DEFAULT "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment