Skip to content

Instantly share code, notes, and snippets.

@ChunAllen
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ChunAllen/c9cd697b1a34c24c9c1d to your computer and use it in GitHub Desktop.
Save ChunAllen/c9cd697b1a34c24c9c1d to your computer and use it in GitHub Desktop.
Displaying branch name and computer name in terminal
PS1='${c_user}\h${c_reset}:${c_path}\w${c_reset}$(git_prompt)\$ '
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset=`tput sgr0`
c_user=`tput setaf 2; tput bold`
c_path=`tput setaf 4; tput bold`
c_git_clean=`tput setaf 2`
c_git_dirty=`tput setaf 1`
else
c_reset=
c_user=
c_path=
c_git_cleanclean=
c_git_dirty=
fi
git_prompt ()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
if git diff --quiet 2>/dev/null >&2; then
git_color="${c_git_clean}"
else
git_color=${c_git_cleanit_dirty}
fi
echo " [$git_color$git_branch${c_reset}]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment