Skip to content

Instantly share code, notes, and snippets.

@delr3ves
Last active December 23, 2015 00:19
Show Gist options
  • Save delr3ves/6552933 to your computer and use it in GitHub Desktop.
Save delr3ves/6552933 to your computer and use it in GitHub Desktop.
Show the current git branch you're working and whether it's dirty in your prompt
# Regular Colors
Black="\[\033[0;30m\]" # Black
Red="\[\033[0;31m\]" # Red
Green="\[\033[0;32m\]" # Green
Yellow="\[\033[0;33m\]" # Yellow
Blue="\[\033[0;34m\]" # Blue
Purple="\[\033[0;35m\]" # Purple
Cyan="\[\033[0;36m\]" # Cyan
White="\[\033[0;37m\]" # White
Color_Off="\[\033[0m\]"
# Various variables you might want for your PS1 prompt instead
PathShort="\w"
PathFull="\W"
export PS1=$Color_Off'$(git branch &>/dev/null;\
if [ $? -eq 0 ]; then \
echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \
if [ "$?" -eq "0" ]; then \
# @4 - Clean repository - nothing to commit
echo "'$Green'"$(__git_ps1 "(%s)");\
else \
# @5 - Changes to working tree
echo "'$Red'"$(__git_ps1 "{%s}");\
fi) '$Yellow$PathShort$Color_Off$Purple\€$Color_Off' ";\
else \
# @2 - Prompt when not in GIT repo
echo "\u\[\033[00;31m\]@\[\033[01;36m\]\h\[\033[01;33m\]'$Yellow$PathShort$Color_Off$Purple\€$Color_Off'"; \
fi)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment