Created
April 2, 2012 19:30
-
-
Save jqno/2286576 to your computer and use it in GitHub Desktop.
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 GREEN="\[\033[01;32m\]" | |
local YELLOW="\[\033[01;33m\]" | |
local BLUE="\[\033[01;34m\]" | |
local WHITE="\[\033[00m\]" | |
local PROMPT="" | |
# Working directory | |
PROMPT=$PROMPT"$GREEN\w" | |
# 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" $RED(" | |
# Branch | |
PROMPT=$PROMPT$(git branch --no-color 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/\1/") | |
# Warnings | |
PROMPT=$PROMPT$YELLOW | |
# Merging | |
if [[ $GIT_STATUS =~ 'Unmerged paths' ]] | |
then | |
PROMPT=$PROMPT"|MERGING" | |
# Dirty flag | |
elif [[ $GIT_STATUS =~ 'nothing to commit (working directory clean)' ]] | |
then | |
PROMPT=$PROMPT | |
else | |
PROMPT=$PROMPT"*" | |
fi | |
# Warning for no email setting | |
if [[ $(git config user.email) =~ ^$ ]] | |
then | |
PROMPT=$PROMPT" !!! NO EMAIL SET !!!" | |
fi | |
# Closing paren | |
PROMPT=$PROMPT"$RED)" | |
fi | |
# Final $ symbol | |
PROMPT=$PROMPT"$BLUE\$$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