Git/color prompt: Difference between revisions

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< Git
No edit summary
No edit summary
Line 7: Line 7:
</syntaxhighlight>
</syntaxhighlight>
I ''think'' the location is significant; in my files, it's right after PS1 is first defined.
I ''think'' the location is significant; in my files, it's right after PS1 is first defined.
* Note 2023-04-04: Adding it at the end of the file also works, but may override non-Git colors.


Example of what this looks like:<br>
Example of what this looks like:<br>
[[File:2023-01-08.bash git prompt.png]]
[[File:2023-01-08.bash git prompt.png]]

Revision as of 20:39, 4 April 2023

To show the status of the current project in the bash prompt, using color, add this to ~/.bashrc:

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[01;32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

I think the location is significant; in my files, it's right after PS1 is first defined.

  • Note 2023-04-04: Adding it at the end of the file also works, but may override non-Git colors.

Example of what this looks like: