Last active
June 13, 2016 14:22
-
-
Save j-alberto/5383f29cfaca3ed72d83aa9c1e5ae646 to your computer and use it in GitHub Desktop.
git-aware prompt with custom coloring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _fancy_prompt { | |
local RED="\[\033[01;31m\]" | |
local YELLOW="\[\033[01;33m\]" | |
local BLUE="\[\033[01;34m\]" | |
local WHITE="\[\033[00m\]" | |
local GREEN="\[\033[36m\]" | |
local GREEN2="\[\033[32m\]" | |
local PROMPT="" | |
# user@host$working/directory | |
# PROMPT="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[m\]\$\[\033[33;1m\]\w\[\033[m\]" | |
PROMPT="$GREEN\u$WHITE@$GREEN2\h$WHITE\$$YELLOW\w$WHITE" | |
# Git-specific | |
local GIT_STATUS=$(git status 2> /dev/null) | |
if [ -n "$GIT_STATUS" ] # Are we in a git directory? | |
then | |
# Open paren | |
PROMPT=$PROMPT"$BLUE($WHITE" | |
# Branch | |
PROMPT=$PROMPT$(git branch --no-color 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/\1/") | |
# Warnings | |
PROMPT=$PROMPT$YELLOW | |
# Merging | |
echo $GIT_STATUS | grep "Unmerged paths" > /dev/null 2>&1 | |
if [ "$?" -eq "0" ] | |
then | |
PROMPT=$PROMPT"|MERGING" | |
fi | |
# Dirty flag | |
echo $GIT_STATUS | grep "nothing to commit" > /dev/null 2>&1 | |
if [ "$?" -eq 0 ] | |
then | |
PROMPT=$PROMPT | |
else | |
PROMPT=$PROMPT"*" | |
fi | |
# Warning for no email setting | |
git config user.email | grep @ > /dev/null 2>&1 | |
if [ "$?" -ne 0 ] | |
then | |
PROMPT=$PROMPT" !!! NO EMAIL SET !!!" | |
fi | |
# Closing paren | |
PROMPT=$PROMPT"$BLUE)" | |
fi | |
# Final $ symbol | |
# PROMPT=$PROMPT"$BLUE\$$WHITE " | |
PROMPT=$PROMPT"$WHITE " | |
export PS1=$PROMPT | |
} | |
export PROMPT_COMMAND="_fancy_prompt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add a line in your .profile file:
. {path-to-file}/.git-prompt