Skip to content

Instantly share code, notes, and snippets.

@ashikahmad
Last active December 29, 2015 11:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ashikahmad/7661870 to your computer and use it in GitHub Desktop.
Save ashikahmad/7661870 to your computer and use it in GitHub Desktop.
A pretty prompt for terminal or iTerm. (Inspired by this link: https://github.com/Lokaltog/powerline). Check attached images to see what to achieve. Check pretty_prompt_HowTo.md for instructions.
# Install and use menlo font-patch from: https://gist.github.com/qrush/1595572
# Setting GIT prompt
b_black=`tput setab 0`
b_red=`tput setab 9`
b_green=`tput setab 2`
b_cyan=`tput setab 14`
b_white=`tput setab 15`
f_black=`tput setaf 0`
f_red=`tput setaf 9`
f_green=`tput setaf 2`
f_cyan=`tput setaf 14`
f_gray=`tput setaf 8`
f_white=`tput setaf 15`
c_clear=`tput sgr0`
branch_color ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
color=""
if git diff --quiet 2>/dev/null >&2
then
color=${b_green}
else
color=${b_red}
fi
else
# return 0
echo -n ${b_white}
fi
echo -n $color
}
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver="⮀⭠["$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')"]"
else
return 0
fi
echo -e $gitver
}
#It's important to escape colors with \[ to indicate the length is 0
PS1='\n\[${b_cyan}${f_black}\] \u \[${b_white}${f_cyan}\]⮀\[${f_black}\] \W \[${f_white}$(branch_color)\]$(parse_git_branch)\[${b_white}${f_white}\] \[${c_clear}${f_white}\]⮀\[${c_clear}\] '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment