Skip to content

Instantly share code, notes, and snippets.

@aaronblenkush
Forked from jqno/fancy-prompt.sh
Last active December 23, 2015 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronblenkush/6703609 to your computer and use it in GitHub Desktop.
Save aaronblenkush/6703609 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 echo $GIT_STATUS | grep -E 'Unmerged paths' > /dev/null
then
PROMPT=$PROMPT"|MERGING"
# Dirty flag
elif echo $GIT_STATUS | grep -E 'nothing to commit (working directory clean)' > /dev/null
then
PROMPT=$PROMPT
else
PROMPT=$PROMPT"*"
fi
# Warning for no email setting
if echo $(git config user.email) | grep -E ^$ > /dev/null
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"
@aaronblenkush
Copy link
Author

Forked to make it compatible with Git for Windows, which doesn't support the ~= regex operator (see http://stackoverflow.com/questions/15510083/syntax-error-operator-in-msysgit-bash).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment