Skip to content

Instantly share code, notes, and snippets.

@dinusuresh
Last active March 16, 2017 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinusuresh/188aae63982f0a4da85623ef701a40d5 to your computer and use it in GitHub Desktop.
Save dinusuresh/188aae63982f0a4da85623ef701a40d5 to your computer and use it in GitHub Desktop.
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