Skip to content

Instantly share code, notes, and snippets.

@sndwch
Last active August 29, 2015 14:24
Show Gist options
  • Save sndwch/ec8d7f7b1674bde56e1b to your computer and use it in GitHub Desktop.
Save sndwch/ec8d7f7b1674bde56e1b to your computer and use it in GitHub Desktop.
.bashrc
# Configure colors, if available.
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset='\[\e[0m\]'
c_user='\[\033[1;33m\]'
c_path='\[\e[0;33m\]'
c_git_clean='\[\e[0;36m\]'
c_git_dirty='\[\e[0;35m\]'
else
c_reset=
c_user=
c_path=
c_git_clean=
c_git_dirty=
fi
# Function to assemble the Git part of our prompt.
git_prompt ()
{
GIT_DIR=`git rev-parse --git-dir 2>/dev/null`
if [ -z "$GIT_DIR" ]; then
return 0
fi
GIT_HEAD=`cat $GIT_DIR/HEAD`
GIT_BRANCH=${GIT_HEAD##*/}
if [ ${#GIT_BRANCH} -eq 40 ]; then
GIT_BRANCH="(no branch)"
fi
refresh=`git update-index --refresh 2>/dev/null`
if [ -z "$refresh" ]; then
git_color="${c_git_clean}"
else
git_color="${c_git_dirty}"
fi
echo "[$git_color$GIT_BRANCH$c_reset]"
}
PROMPT_COMMAND='PS1="${c_user}\u${c_reset}@${c_user}\h${c_reset}:${c_path}\w${c_reset}$(git_prompt)\$ "'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment