Last active
November 4, 2016 08:00
-
-
Save pyrtsa/1616902 to your computer and use it in GitHub Desktop.
git-ps1
This file contains hidden or 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 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 | |
} |
This file contains hidden or 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
source ~/.git-ps1.bash | |
git-ps1 on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
(orgit-ps1 no
orgit-ps1 n
).