Add Git Branch Name to Terminal Prompt (Mac)


#21

thanks!


#22

Awesome. Thanks.


#23

merci


#24

if you use this, you’ll have coloured terminal with git branch:

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

#25

I use this call to get the current branch.
You need not sed stuff.

git rev-parse --abbrev-ref HEAD


#26

Neat, any way to get this to wrap the branch in ( and ) (i.e. keep the same formatting) within the parse_git_branch function? (and without them showing up when there is no branch)


#27

hey man, nice! thank you.


#28

THANK YOU!


#29

very nice, Thanks :)


#30

I ended up adding timestamp to that , it helped a lot of times trying to find out what I did and when.
In case someone needs it.

# Git branch in prompt.
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

export PS1="\[\e[0;35m\]\@\[\e[m\] @\[\033[33;1m\]\w\[\033[m\]:\[\033[36m\]\$(parse_git_branch)\[\033[m\]$ "

parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}


#31

where's the timestamp portion if you don't mind, and is it on the far right?


#32

This is the part.

\[\e[0;35m\]\@\[\e[m\]


#33

Thank you !


#34

Works perfect for me. Thank you for sharing.


#35

Got `-bash: @: command not found`
On Sierra 10.12.3


#36

Excelent Post Martin!!! Works like a charm on Sierra 10.12.3


#37

I have a ~/.bash_profile.save file. Is that the same as ~/.bash_profile ?


#38

Answering my own question -- it's not the same.


#39

Simple to setup on OS X 10.11.6 and iterm. Thumbs up.


#40

Great article / tutorials.