Skip to content

Instantly share code, notes, and snippets.

@dakaktus
Created June 18, 2012 11:12
Show Gist options
  • Save dakaktus/2947909 to your computer and use it in GitHub Desktop.
Save dakaktus/2947909 to your computer and use it in GitHub Desktop.
bash:git:show colorize repository path and display current branch
#!/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$ "
@dakaktus
Copy link
Author

Just put above in .bashrc file

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