Created
June 20, 2012 14:13
-
-
Save ktilcu/2960100 to your computer and use it in GitHub Desktop.
Bash prompt for git branches
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
# Note that a variable may require special treatment | |
#+ if it will be exported. | |
DARKGRAY='\e[1;30m' | |
LIGHTRED='\e[0;31m' | |
GREEN='\e[32m' | |
YELLOW='\e[1;33m' | |
LIGHTBLUE='\e[1;34m' | |
NC='\e[m' | |
COLOR_OFF="\[\e[0m\]" | |
function prompt_func(){ | |
pgd=`git rev-parse --show-toplevel 2>/dev/null` | |
branch_pattern="\* ([^$IFS]*)" | |
if [[ -d $pgd"/.git" && "$(git branch --no-color 2> /dev/null)" =~ $branch_pattern ]]; then | |
branch="${BASH_REMATCH[1]}" | |
if [ "$branch" = "(no" ]; then | |
branch="Detached Head" | |
fi | |
PS1="[\[\033[32m\]\w$NC:$LIGHTRED$branch$COLOR_OFF]\[\033[0m\]\n\[\033[1;36m\]\u\[\033[1;33m\]-> \[\033[0m\]" | |
else | |
PS1="[\[\033[32m\]\w$NC]\[\033[0m\]\n\[\033[1;36m\]\u\[\033[1;33m\]-> \[\033[0m\]" | |
fi | |
#PS1+=":$LIGHTBLUE$branch$COLOR_OFF" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment