I've been watching some of the Team Treehouse videos and they have a very nice looking terminal when working with Git.
For example they have (something similar):
mike@treehouseMac: [/Work/test - feature-branch-name] $ git add . mike@treehouseMac: [/Work/test - feature-branch-name] $ git commit -m "Some feature." mike@treehouseMac: [/Work/test - feature-branch-name] $ git checkout master mike@treehouseMac: [/Work/test - master] $ git status
How can my terminal show me some useful information of what branch I'm on, with colors to distinguish bits of the data I want? Is there some sort of de-facto plugin I haven't found yet?
I'm using Mac OSX 10.8
For anyone looking for how to do this in macOS Catalina or above (10.15+ incl. Big Sur 11.0) which has deprecated bash in favour of zsh, here is my .zshrc file:
parse_git_branch() { git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p' } COLOR_DEF='%f' COLOR_USR='%F{243}' COLOR_DIR='%F{197}' COLOR_GIT='%F{39}' NEWLINE=$'\n' setopt PROMPT_SUBST export PROMPT='${COLOR_USR}%n@%M ${COLOR_DIR}%d ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}${NEWLINE}%% '
If you don't like the colours I have used, replace the 243/197/39 values with the colour codes as defined here: https://misc.flogisoft.com/bash/tip_colors_and_formatting
Simple way
Open ~/.bash_profile
in your favorite editor and add the following content to the bottom.
Git branch in prompt.
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export PS1="\u@\h \[\033[32m\]\w - \$(parse_git_branch)\[\033[00m\] $ "
Add Git Branch To Terminal Prompt (Mac)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With