Skip to content

Instantly share code, notes, and snippets.

@jqno
Created April 2, 2012 19:30
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 jqno/2286576 to your computer and use it in GitHub Desktop.
Save jqno/2286576 to your computer and use it in GitHub Desktop.
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