Created
June 18, 2012 11:12
-
-
Save dakaktus/2947909 to your computer and use it in GitHub Desktop.
bash:git:show colorize repository path and display current branch
This file contains 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
#!/bin/bash | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
find_git_path(){ | |
CURRENT_PATH='/' | |
DIRECTORY='/.git' | |
DIRECTORY_BUFFOR='' | |
if [ -d $DIRECTORY ]; then | |
DIRECTORY_BUFFOR="\e[1;32m" | |
else | |
DIRECTORY_BUFFOR="" | |
fi | |
CURRENT_PATH='' | |
for GIT_PATH in $(pwd | tr -s '/' '\n') | |
do | |
DIRECTORY="$CURRENT_PATH/$GIT_PATH/.git" | |
if [ -d $DIRECTORY ]; then | |
CURRENT_PATH="${CURRENT_PATH}\e[1;32m/${GIT_PATH}" | |
else | |
CURRENT_PATH="${CURRENT_PATH}/${GIT_PATH}" | |
fi | |
done | |
echo -e $CURRENT_PATH | |
} | |
PS1="\$(find_git_path)\e[1;31m \$(parse_git_branch)\e[1;37m$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just put above in .bashrc file