Skip to content

Instantly share code, notes, and snippets.

@dinusuresh dinusuresh/.bashrc
Last active Mar 16, 2017

Embed
What would you like to do?
View git branch name and user email on terminal
# BEGIN -- git branch
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ >> \1 <</'
}
parse_git_email() {
BRANCH="$(parse_git_branch)"
#echo -ne "$BRANCH"
if [ -n "$BRANCH" ]; then
git config user.email
fi
}
# END -- git branch
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;32m\]$(parse_git_branch)\[\033[00m\] \[\033[01;37m\]$(parse_git_email)\[\033[00m\]
$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$(parse_git_branch)\$(parse_git_email)
$ '
fi
For Ubuntu
Edit ~/.bashrc file.
Locate the "if [ "$color_prompt" = yes ]; then else" block
Replace with the code in .bashrc file mentioned in this gist
Save file
Close and open terminal or perform `source ~/.bashrc`
Result:
maximus@Rome:~/sites/rome.city >> master << maximus@peekaboo.com
$ git checkout feature-colosseum
maximus@Rome:~/sites/rome.city >> feature-colosseum << maximus@peekaboo.com
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.