When I use Windows, the shell (even a standard Windows shell) shows basic information about the git repository when you are in a git repository. Things like the active branch and maybe some color coding.
Is there a way to have the same in Ubuntu?
The Windows Git shell, which is really just bash, sets the prompt $PS1
to a long string that includes $(__git_ps1)
.
__git_ps1
is defined as a function, nearly 100 lines long, that prints the name of the current branch in parentheses.
/etc/profile
(which is C:\Program Files (x86)\Git\etc\profile
, at least on my system)) invokes /etc/git-completion.bash
, which defines the __git_ps1
function, sets $PS1
, defines some git-specific completions, among other things.
The git-completion.bash
used by Git Bash appears to be based on this.
If you use zsh as your shell, you might find my config files useful. Try source prompt/blocky
to see what the prompt looks like in a Git repository.
How to stop bash prompt colours from escaping has an example. You could copy it from the answer and then use gedit to paste it to the bottom of your the .bashrc file in your home directory (making a backup, first, of course).
If the .bashrc file Keith mentions in his answer is part of git it will be licensed with GPL2 so you should be free to past it into your .bashrc file as well. You'll have to grab the /etc/git-completion.bash file and install it somewhere too, and have your new .bashrc reference it.
Here's something else you could paste and try from Arturo Fernandez at http://www.bsnux.com/recipes/how-display-you-current-git-branch-prompt.html
# Displaying git branch inside prompt function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } function proml { local GREEN="\[\033[0;32m\]" local WHITE="\[\033[0;37m\]" PS1="[\u@\h \w$GREEN\$(parse_git_branch)]$WHITE\$ " PS2='> ' PS4='+ ' } proml
Here's how to add windows-like git-bash to Ubuntu terminal:
~/.bashrc
:PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '
source ~/.bashrc
git-core
package installed?