Skip to content

Instantly share code, notes, and snippets.

@mzaragoza
Created September 11, 2013 19:29
Show Gist options
  • Save mzaragoza/6528597 to your computer and use it in GitHub Desktop.
Save mzaragoza/6528597 to your computer and use it in GitHub Desktop.
You can add the following code to you .bashrc file:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$(parse_git_branch) $ "
You can move around these component parts to configure to your tastes, for example to prepend $(parse_git_branch) and not show the user@computer part I used:
PS1="\$(parse_git_branch)${debian_chroot:+($debian_chroot)}\w$ "
Which displays:
(master)~/my_projects/project_x$
See also: What is this PS1 variable doing in .bash_profile file?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment