Prompt for command line including git branch

in my .bashrc in ~ Put the following:  

#⚡ cat .bashrc
export EDITOR=/usr/bin/vim

if [ -f /opt/local/etc/bash_completion ]; then
        . /opt/local/etc/bash_completion
fi

set -o vi

alias ll='ls -l'

showBranch(){
    if [$(pwd | grep "projects|www") != ""]; then
        git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/±\1/' | tr "\n" ' '
        hg branch 2> /dev/null | sed -e 's/\(.*\)/☿\1 /'
    fi
}

export PS1='\e[01;32m\u\e[34m@\H \e[01;31m\w \e[32;40m$(showBranch) \n\[\e[30m\]#\[\e[33m\]⚡ \[\e[0m\]'



Notes
- type "bash" on command line to see latest changes take effect
- in the if stmt in showBranch() you should put the folder in which you put your repos, e.g. for me my code is always under a folder named work, so the if is: if [$(pwd | grep "work|www") != ""]; then
- more reading here useful article
- thanks to my buddy Jonah for this little beauty

Comments

Popular posts from this blog

deep dive into Material UI TextField built by mui

angular js protractor e2e cheatsheet

react-router v6.4+ loaders, actions, forms and more