Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
Last active November 4, 2016 08:00
Show Gist options
  • Save pyrtsa/1616902 to your computer and use it in GitHub Desktop.
Save pyrtsa/1616902 to your computer and use it in GitHub Desktop.
git-ps1
function git-ps1 {
case $1 in
y|yes|on)
export GIT_PS1_SHOWDIRTYSTATE=yes
export GIT_PS1_SHOWUNTRACKEDFILES=yes
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
export PS1='\[\e[0m\e[36m\]\u@\h \[\e[1;39m\]\w\[\e[0;32m\]$(__git_ps1 " (%s)")\[\e[0m\] \\$ ';
else
export PS1='\[\e[0m\e[31m\]\u \[\e[1;39m\]\w\[\e[0;32m\]$(__git_ps1 " (%s)")\[\e[0m\] \\$ ';
fi
echo
;;
n|no|off)
export GIT_PS1_SHOWDIRTYSTATE=no
export GIT_PS1_SHOWUNTRACKEDFILES=no
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
export PS1='\[\e[0m\e[36m\]\u@\h \[\e[1;39m\]\w\[\e[0m\] \\$ ';
else
export PS1='\[\e[0m\e[31m\]\u \[\e[1;39m\]\w\[\e[0m\] \\$ ';
fi
echo
;;
*) echo 'usage: git-ps1 (y|yes|on|n|no|off)' ;;
esac
}
source ~/.git-ps1.bash
git-ps1 on
@pyrtsa
Copy link
Author

pyrtsa commented Oct 7, 2014

Put .git-ps1.bash to your home directory ~ and add the lines from .profile to your .profile (or .bashrc or whatever). Your new Bash prompt will show in green your current Git branch and whether there are staged (+) or unstaged (*) changes or untracked files (%).

If you're working with a huge repository and updating the prompt is taking a lot of time, you can temporarily turn off the green part by calling git-ps1 off (or git-ps1 no or git-ps1 n).

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