Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display git branch in bash prompt
# If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer!
export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ "
# This will change your prompt to display not only your working directory but also your current git branch, if you have one. Pretty nifty!
# ~/code/web:beta_directory$ git checkout master
# Switched to branch "master"
# ~/code/web:master$ git checkout beta_directory
# Switched to branch "beta_directory"
# ~/code/web:beta_directory$
@dregad

This comment has been minimized.

Copy link

@dregad dregad commented Nov 19, 2011

Why not simply use the __git_ps1 function ?

export PS1="\\w\$(__git_ps1 '(%s)') \$ "
@bjlbernal

This comment has been minimized.

Copy link

@bjlbernal bjlbernal commented May 24, 2013

__git_ps1 didn't work for me on my MacBook Pro.

-bash: __git_ps1: command not found

Resorted back to original post.

@keegan2149

This comment has been minimized.

Copy link

@keegan2149 keegan2149 commented Aug 19, 2013

Added the hostname

export PS1="\h\w:$(git branch 2>/dev/null | grep '^*' | colrm 1 2)$ "

@wayneseymour

This comment has been minimized.

Copy link

@wayneseymour wayneseymour commented Jan 30, 2014

Thanks man.
So far I'm at:

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \$ "
# gives me:
wayne  ~/dev/lrn (master) $ # my name in green, curr dir in yellow, and branch in green

Still a WIP.

:)

@dontfeedthecode

This comment has been minimized.

Copy link

@dontfeedthecode dontfeedthecode commented Jun 19, 2014

Try

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \$  \n| => "
export PS2="| => "

Depending what directory you're in the line gets a bit long, this starts the actual in put on the line below.

@navyad

This comment has been minimized.

Copy link

@navyad navyad commented Aug 7, 2014

how to color the branch name ?

@vankasteelj

This comment has been minimized.

Copy link

@vankasteelj vankasteelj commented Mar 7, 2016

I'll leave this here:

PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '

capture_du_2016-03-07_19-13-07

@LeoFNaN

This comment has been minimized.

Copy link

@LeoFNaN LeoFNaN commented Aug 26, 2016

Now that's a nice one @vankasteelj...(__git_ps1) doesn't work in my terminal on xubuntu so I substituted it with this gists original display method and removed the chevron symbol (personal preference)

PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[0;32m\]\n$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] '

@husnulhamidiah

This comment has been minimized.

Copy link

@husnulhamidiah husnulhamidiah commented Aug 28, 2016

How to change (master) to [master]

@jhit

This comment has been minimized.

Copy link

@jhit jhit commented Sep 10, 2016

if __git_ps1 is not working take a look here: https://fedoraproject.org/wiki/Git_quick_reference
I needed to add source /usr/share/git-core/contrib/completion/git-prompt.sh to my ~/.bashrc to get it work.

@MrAaronOlsen

This comment has been minimized.

Copy link

@MrAaronOlsen MrAaronOlsen commented Jun 1, 2017

I like this! __git_ps1 seems to force () around my branch and adds a space in front of it. Your option allows me to not have that which looks cleaner to me. If clutter in the ps1 string isn't desirable then folks always have the option of putting it in a bash function.

git_branch() {
  git branch 2>/dev/null | grep '^*' | colrm 1 2
}

export PS1="\$(git_branch)"

Gone are the days of working on master by accident... Thanks again!

@javieitez

This comment has been minimized.

Copy link

@javieitez javieitez commented Jun 28, 2017

The problem with PS1="\$(git_branch)"' is that it displays the empty parenthesis () when the current dir is not a git one. I've tweaked it like this to get rid of them.

gb() {
        echo -n '(' && git branch 2>/dev/null | grep '^*' | colrm 1 2 | tr -d '\n' && echo  -n ')'
}
git_branch() {
        gb | sed 's/()//'
}

It needs two functions because if we pipe everything into one line, the last sed command that strips the () doesn't receive the right input (notice the &&).

@giannidk

This comment has been minimized.

Copy link

@giannidk giannidk commented Jul 8, 2017

I made a small modification to @vankasteelj version, with square brackets around the branch name:

PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[0;32m\] - [$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[0;32m\]]\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] '

screen shot 2017-07-08 at 16 51 57

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 15, 2017

Yet another variant, with a couple of nice features. First, I use PROMPT_COMMAND instead of PS1 to get coloured info, second I use GIT_PS1_SHOWDIRTYSTATE=1, GIT_PS1_SHOWCOLORHINTS=1,GIT_PS1_SHOWUNTRACKEDFILES=1 to turn on all the features.

Also, with long prompt strings, you almost certainly want a newline in there near the end, so that there is plenty of space on each line.

So putting it all together:

export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWCOLORHINTS=1
export GIT_PS1_SHOWUNTRACKEDFILES=1

export PROMPT_COMMAND=' __git_ps1 "\n[\e[33m][[\e[m]\A [\e[31m]\u[\e[m]@[\e[32m]\h [\e[34;01m]\l[\e[m] [\e[36m]\w[\e[m]" "[\e[33m]][\e[m]\n$ "'

which gives this sort of thing:

bash_git

@skimpa

This comment has been minimized.

Copy link

@skimpa skimpa commented Sep 20, 2017

thanks guys ...helped me get what i was looking for
gitpic

@megadr01d

This comment has been minimized.

Copy link

@megadr01d megadr01d commented Sep 24, 2017

With brew install git:

source /usr/local/etc/bash_completion.d/git-prompt.sh
export PS1="\w\$(__git_ps1 '[%s]') $ "
@dagolinuxoid

This comment has been minimized.

Copy link

@dagolinuxoid dagolinuxoid commented Oct 5, 2017

@gordboy somehow I've got a LOT of additional redundant empty brackets using your set up | definitely I messed up on something :)
threre is my old .bashrc

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

#### Change terminal title
PROMPT_COMMAND='echo -ne "\033]0;${PWD}\007"'

@samsoul16

This comment has been minimized.

Copy link

@samsoul16 samsoul16 commented Oct 13, 2017

@skimpa can you share your PS1 i liked the style that you have created and i want to use the same one.

@stucash

This comment has been minimized.

Copy link

@stucash stucash commented Oct 18, 2017

@vankasteelj a year later still working like a charm on ubuntu 16.04, nicely done. thanks a lot

@fritzmatias

This comment has been minimized.

Copy link

@fritzmatias fritzmatias commented Nov 9, 2017

@iuliaL

This comment has been minimized.

Copy link

@iuliaL iuliaL commented Jan 9, 2018

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

export PS1="\u@\[\033[32m\]\w\[\033[33m\]\$(git_branch)\[\033[00m\]\$ " 

optional parenthesis 💯

@niketpathak

This comment has been minimized.

Copy link

@niketpathak niketpathak commented Jan 10, 2018

Another version along with the status of your current branch (dirty, stashed content, etc)
http://digitalfortress.tech/tutorial/setting-up-git-prompt-step-by-step/

@tzago

This comment has been minimized.

Copy link

@tzago tzago commented Feb 8, 2018

Using vankasteelj version on debian strech and working as expected. Thank you guys!!!

@zenglian

This comment has been minimized.

Copy link

@zenglian zenglian commented Mar 9, 2018

Use a different color for the branch name?

@prophetnoise

This comment has been minimized.

Copy link

@prophetnoise prophetnoise commented Mar 16, 2018

As an alternative, i wanted my Terminal (mac) window's title to display the branch as i navigated instead of the prompt. Added the https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh file to my home directory as .git-prompt-sh

Added to my .bash_profile:

if [ -f ~/.git-prompt.sh ]; then
  source ~/.git-prompt.sh
fi

function cd () { builtin cd "$@" && printf "\033]0;$(__git_ps1 '%s')\007"; }
function checkout () { git checkout "$@" && printf "\033]0;$(__git_ps1 '%s')\007"; }
@khadijanazih

This comment has been minimized.

Copy link

@khadijanazih khadijanazih commented Mar 22, 2018

I used this:

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \$ "

it worked fine for me but I want to shorten the path to this : [user]@[current directory](current branch) with the colors of course.

How can I do it !!

@jeroendesloovere

This comment has been minimized.

Copy link

@jeroendesloovere jeroendesloovere commented Apr 26, 2018

@khadijanazih, use the following (from @giannidk and @vankasteelj):
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[0;32m\] - [$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[0;32m\]]\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] '

@rioj7

This comment has been minimized.

Copy link

@rioj7 rioj7 commented May 2, 2018

@vankasteelj some color commands are not needed, removing gives the following prompt

PS1='\[\033[32m\]\u \[\033[36m\]@ \h \w\[\033[32m\]$(__git_ps1)\n└─ \$ ▶\[\033[0m\] '
@niketpathak

This comment has been minimized.

Copy link

@niketpathak niketpathak commented May 25, 2018

You could even color the git prompt depending on the state of your repository. For example, "Red" if there are any changes in the repo, "Green" otherwise, etc...
Setup up Git prompt

@ishitvagoel

This comment has been minimized.

Copy link

@ishitvagoel ishitvagoel commented Jul 26, 2018

We can now even copy paste emojis in the PS1 prompt string.
Added three emojis to the version specified by @vankasteelj

Screenshot:
https://screenshots.firefox.com/pOjRfrgZMXbnaUHP/null

@Iqlaas

This comment has been minimized.

Copy link

@Iqlaas Iqlaas commented Jul 30, 2018

screen shot 2018-07-30 at 3 34 36 pm
Hi All. How do I do it like above ? Dont mind the emoji, I know its representing the user's machine name.

It shows only the repository name, (not including its path if it were to go into a subfolder), git:(current branch), and some x.
Tried to search online but could not find any.

So in short (user)@(repo name only)git:(current branch)(space)x

Sorry I forgot I am using zsh.
Please help! Thank you!

@bl4ck4ndbr0wn

This comment has been minimized.

Copy link

@bl4ck4ndbr0wn bl4ck4ndbr0wn commented Aug 18, 2018

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

image

@sibasishm

This comment has been minimized.

Copy link

@sibasishm sibasishm commented Aug 26, 2018

@vankasteelj working on Debian 16.04 and it's working like a charm. Thank you. However this change is not permanent in my case, I have to reload bash_profile every time I open a new terminal. Any fix for that?
PS: this thread is gold!

@hansfn

This comment has been minimized.

Copy link

@hansfn hansfn commented Sep 7, 2018

Why aren't you using git symbolic-ref HEAD --short instead of git branch and grepping for stars?

@shivakumargn

This comment has been minimized.

Copy link

@shivakumargn shivakumargn commented Sep 14, 2018

@hansfn, that is indeed better than git branch. 'git branch` can be visibly slow to show the prompt on large repos with lots of branches.

@nnungest

This comment has been minimized.

Copy link

@nnungest nnungest commented Sep 18, 2018

@Sibasish19 you can add this to your ~/.bashrc instead if you'd like.

@hansfn

This comment has been minimized.

Copy link

@hansfn hansfn commented Sep 20, 2018

vankasteelj wrote on Mar 7, 2016

I'll leave this here:

PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '

capture_du_2016-03-07_19-13-07

Isn't there just too much going on? Even more unreadable than normal ;-) The following should be the same.

PS1='\[\033[0;32m\]\u\[\033[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0;32m\] \$\[\033[0;32m\] ▶\[\033[0m\] '

If you in addition remember that a color sticks until is changed or reset, we get:

PS1='\[\033[0;32m\]\u\[\033[0;36m\] @ \h \w\[\033[0;32m\]$(__git_ps1)\n└─ ▶\[\033[0m\] '

I'm just mentioning this in case people copies vankasteelj code and tries to understand it ...

PS! Reading Bash Prompt HOWTO: Colors and https://bash.cyberciti.biz/guide/Changing_bash_prompt is very useful.

@nemopohle

This comment has been minimized.

Copy link

@nemopohle nemopohle commented Sep 27, 2018

All I wanted is a simple, colored one-line prompt. @vankasteelj provided a nice one, I just extended it by not displaying brackets when outside a repo:

PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[0;32m\]$(if git rev-parse --git-dir > /dev/null 2>&1; then echo " - ["; fi)$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[0;32m\]$(if git rev-parse --git-dir > /dev/null 2>&1; then echo "]"; fi)\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] '

@weilinzung

This comment has been minimized.

Copy link

@weilinzung weilinzung commented Sep 28, 2018

Is possible to add the current branch name on all the timestamp lines? Something like this:

FROM:

[18:37:39] Starting 'build-js'...
[18:37:49] finished 'build-js'...

TO:

[18:37:39 - **current-branch-name** ] Starting 'build-js'...
[18:37:49 - **current-branch-name** ] finished 'build-js'...

Thanks.

@cornensue

This comment has been minimized.

Copy link

@cornensue cornensue commented Sep 29, 2018

I like this one, thanks:

PS1='[\033[0;32m][\033[0m\033[0;32m]\u[\033[0;36m] @ [\033[0;36m]\h \w[\033[0;32m]$(__git_ps1)\n[\033[0;32m]└─[\033[0m\033[0;32m] $[\033[0m\033[0;32m] [\033[0m] '

@jedmao

This comment has been minimized.

Copy link

@jedmao jedmao commented Oct 4, 2018

I like this short directory formatting:

screen shot 2018-10-04 at 5 05 23 pm copy

function shortwd() {
    num_dirs=3
    pwd_symbol="..."
    newPWD="${PWD/#$HOME/~}"
    if [ $(echo -n $newPWD | awk -F '/' '{print NF}') -gt $num_dirs ]; then
        newPWD=$(echo -n $newPWD | awk -F '/' '{print $1 "/.../" $(NF-1) "/" $(NF)}')
    fi 
    echo -n $newPWD
}

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

PS1='\n\e[38;5;211m$(shortwd)\e[38;5;48m $(git_branch)\e[0m$'
export PS1
@kamok

This comment has been minimized.

Copy link

@kamok kamok commented Oct 12, 2018

I like this better:

Git Aware Prompt - https://github.com/jimeh/git-aware-prompt

export GITAWAREPROMPT=~/.bash/git-aware-prompt
source "${GITAWAREPROMPT}/main.sh"

PS1

export PS1="[$txtblu]\w [$txtgrn]$git_branch[$txtred]$git_dirty[$txtrst]$ "

I use iTerm2, so I can go into the preferences and change $txtblu with a nice UI color picker.

image

@tdwebste

This comment has been minimized.

Copy link

@tdwebste tdwebste commented Oct 23, 2018

pt_user_co() {
    if [ "$(id -u)" == "0" ]; then
        echo -en "\033[1;31m"
    else
        echo -en "\033[1;32m"
    fi
}

pt_host_co() {
    if [[ ${SSH_CLIENT} ]] || [[ ${SSH2_CLIENT} ]]; then 
        echo -en "\033[1;35m"
    else
        echo -en "\033[1;34m"
    fi
}

_git_repo() {
    if type -p __git_ps1; then
#        branch=$(__git_ps1 '%s')
        branch=$(__git_ps1)
        if [ -n "$branch" ]; then 
            subdir=$(git rev-parse --show-prefix 2>/dev/null)
            subdir="${subdir%/}" 
            predir="${PWD%/$subdir}"
            echo -ne "${predir#~}/${subdir}"
        else
            echo -ne ""
        fi
    fi
}

_git_repo_path() {
    if type -p __git_ps1; then
#        branch=$(__git_ps1 '%s')
        branch=$(__git_ps1)
        if [ -n "$branch" ]; then 
            n_remote="$(git remote | wc -l)"
            if [ $n_remote -eq 0 ]; then 
            # no remote repo, no backup red
                c_rem="[1;31m"
            elif [ $n_remote -eq 1 ]; then
            # single remote repo green
                c_rem="[1;32m"
            else
            # multiple remote repo purple
                c_rem="[1;35m"
            fi

            status=$(git status 2> /dev/null)
            if $(echo $status | grep 'added to commit' &> /dev/null); then
            # If we have modified files but no index (blue)
               c_stat="[1;34m"
            else
                if $(echo $status | grep 'to be committed' &> /dev/null); then
                # If we have files in index (red)
                   c_stat="[1;31m"
                else
                # If we are completely clean (green)
                   c_stat="[1;32m"
                fi
            fi

            subdir=$(git rev-parse --show-prefix 2>/dev/null)
            subdir="${subdir%/}" 
            predir="${PWD%/$subdir}"
            echo -ne "\033[01;34m~${predir#~}\033${c_rem}/${subdir}\033${c_stat}"
        else
            echo -ne "\033[01;34m"
        fi
    fi
}

# detect working directory relative to working tree root
pt_git_co() {
    if type -p __git_ps1; then
#        branch=$(__git_ps1 '%s')
        branch=$(__git_ps1)
        if [ -n "$branch" ]; then 
            if [ -n "$1" ]; then
                printf "$1" "${branch}"
            else
                printf "\n%s" "${branch}"
            fi
        else
            printf "%s" "~${PWD#~}"
        fi
    else
        printf "%s" "~${PWD#~}"
    fi
}

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    elif [ "$TERM" = "cygwin" ]; then
	color_prompt=yes
    else
	color_prompt=
    fi
fi


if [ "$color_prompt" = yes ]; then
    #excape \[ non pritable char \]
    PS1='${debian_chroot:+($debian_chroot)}\[$(pt_user_co)\]\u\[\033[0m\]@\[$(pt_host_co)\]\h\[\033[0m\]:\[$(_git_repo_path)\]$(pt_git_co)\[\033[0m\]\$ '
#    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\n$(_git_repo)$(__git_ps1)\$ '
#    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\a\]$PS1"
    ;;
*)
    ;;
esac

@carinlynchin

This comment has been minimized.

Copy link

@carinlynchin carinlynchin commented Oct 24, 2018

how come none of these git branch 2> things are working.. the only way i get my branch is with git rev-parse --abbrev-ref HEAD... thankfully someone else showed that method...https://trueskawka.github.io/blog/programming/2018/01/17/git-branch-in-your-prompt.html

@ldavidsp

This comment has been minimized.

Copy link

@ldavidsp ldavidsp commented Nov 11, 2018

PS1='\n\033[1m** Luis Solorzano \033[1m\u@\h (@) \033[1m** \n\033[1m\w [\033[0;36m]\033[1m$(__git_ps1)\n[\033[01;32m]└─[\033[01;32m]$[\033[0;32m] [\033[0m]'

image

@katiekeel

This comment has been minimized.

Copy link

@katiekeel katiekeel commented Nov 19, 2018

@carinlynchin git branch only shows if you have a commit present in the git repo. I had the same problem and found the answer here.

@jmac88

This comment has been minimized.

Copy link

@jmac88 jmac88 commented Dec 19, 2018

I used this, yet i can't figure out how to get it to leave out the [ ] if I'm not in a repo.

PS1='[\033[1;32m][\033[0m\033[1;32m]\u[\033[1;33m] @ \w[\033[1;32m] - [$(git branch 2>/dev/null | grep "^*" | colrm 1 2)[\033[1;32m]][\033[0m\033[1;32m] $[\033[0m\033[1;32m][\033[0m] '

@MaxKo1987

This comment has been minimized.

Copy link

@MaxKo1987 MaxKo1987 commented Dec 20, 2018

where is __git_ps1 created?

@yx8

This comment has been minimized.

@sergeypapyan

This comment has been minimized.

Copy link

@sergeypapyan sergeypapyan commented Dec 28, 2018

ZSH + OMZ
beautiful and easy with lots of plugins.

(Don't bash me for a non-bash answer))

@archenroot

This comment has been minimized.

Copy link

@archenroot archenroot commented Jan 6, 2019

Ok, so I post mine enhanced by some of nice extensions found here:
image

PS1="\n\[\033[35m\] \$(/bin/date)\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e 's:/dev/::'): \[\033[1;34m\]\$(pwd) \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l |
/bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] \[\033[0m\] \[\033[0;32m\][git:$(git_branch)]\n\[\033[0;32m\] └─\[\033[0m\033[0;32m\] ▶\[\033[0m\]"
@alsanchez-dev

This comment has been minimized.

Copy link

@alsanchez-dev alsanchez-dev commented Jan 7, 2019

Here is Gargula, if anyone of you guys wants to give it a try:

screen shot 2019-01-12 at 7 22 22 am

Gargula adds colors after a theme is defined and adds git status, git branch both are displayed only when git is initialized in a working directory.

Gargula is displaying info that is useful to keep it as much minimalistic as possible.

You can grab it here ---> https://github.com/auniverse4/gargula

@deanrs

This comment has been minimized.

Copy link

@deanrs deanrs commented Jan 13, 2019

a slight color adjustment for some of the suggestions above. Show the branch if we're in a git repo. Show a brown repo name if there's no changes or red if there are changes in the repo.

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

acolor() {
  [[ -n $(git status --porcelain=v2 2>/dev/null) ]] && echo 31 || echo 33
}

export PS1="\u@\[\033[32m\]\w\[\033[\$(acolor)m\]\$(git_branch)\[\033[00m\]\$ "
@eterps

This comment has been minimized.

Copy link

@eterps eterps commented Jan 14, 2019

Without sed:

git_branch() { git describe --contains --all HEAD 2>/dev/null; }
@kfcobrien

This comment has been minimized.

Copy link

@kfcobrien kfcobrien commented Apr 7, 2019

Here is a simple clean version that I use: link

@b1lk0

This comment has been minimized.

Copy link

@b1lk0 b1lk0 commented May 4, 2019

Hello lads,
Ubuntu GNOME default terminal settings looks like:
image
If you need to keep this configuration and only add Git branch recognizer:
image
You can use export command bellow:
export PS1='\[\033[01;32m\]\[\033[0m\033[0;32m\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1)$ '
Just add a line into end of the .bashrc file
vi ~/.bashrc
and don't forget to open a new terminal session!

@jbrodo

This comment has been minimized.

Copy link

@jbrodo jbrodo commented Jun 21, 2019

Hello lads,
Ubuntu GNOME default terminal settings looks like:
image
If you need to keep this configuration and only add Git branch recognizer:
image
You can use export command bellow:
export PS1='\[\033[01;32m\]\[\033[0m\033[0;32m\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1)$ '
Just add a line into end of the .bashrc file
vi ~/.bashrc
and don't forget to open a new terminal session!

Work for me, Thank you!

@stealthman22

This comment has been minimized.

Copy link

@stealthman22 stealthman22 commented Aug 24, 2019

@archenroot so I really like your setup, but the git branch doesn't appear, and can you make it show the status too? thanks

@ameer1234567890

This comment has been minimized.

Copy link

@ameer1234567890 ameer1234567890 commented Aug 29, 2019

What I learnt:

  • git rev-parse --abbrev-ref HEAD returns HEAD instead of branch name, if you do not have at least one commit.
  • git describe --contains --all HEAD returns nothing, if you do not have at least one commit.
  • git branch 2>/dev/null | grep '^*' returns nothing, if you do not have at least one commit.
  • git symbolic-ref HEAD --short always returns branch name, if you even if you do not have any commits.

So, I use git symbolic-ref HEAD --short

@kishorekdty

This comment has been minimized.

Copy link

@kishorekdty kishorekdty commented Sep 16, 2019

I use the following code.

export GIT_PS1_SHOWDIRTYSTATE=1 export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[01;33m\]$(__git_ps1)\[\033[01;34m\] \$\[\033[00m\] '

@3b7ameed

This comment has been minimized.

Copy link

@3b7ameed 3b7ameed commented Oct 26, 2019

Hello lads,
Ubuntu GNOME default terminal settings looks like:
image
If you need to keep this configuration and only add Git branch recognizer:
image
You can use export command bellow:
export PS1='\[\033[01;32m\]\[\033[0m\033[0;32m\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1)$ '
Just add a line into end of the .bashrc file
vi ~/.bashrc
and don't forget to open a new terminal session!

Work for me, Thank you!

Thanks mate

@oknixus

This comment has been minimized.

Copy link

@oknixus oknixus commented Nov 19, 2019

Thanks!
git branch 2>/dev/null | grep '' This line will keep a branches list on the screen after you press q

@Apjo

This comment has been minimized.

Copy link

@Apjo Apjo commented Nov 26, 2019

if __git_ps1 is not working take a look here: https://fedoraproject.org/wiki/Git_quick_reference
I needed to add source /usr/share/git-core/contrib/completion/git-prompt.sh to my ~/.bashrc to get it work.

I tried do this step, but it doesn't seem like I am still able to get a prompt, can you share your bash_profile? I mean does one need to do anything in bash_profile too?This is what I have in my bashrc

#source ~/.config/git-prompt.sh/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true

git_branch() {
  git branch 2>/dev/null | grep '^*' | colrm 1 2
}

export PS1="\$(git_branch)"

#export PS1='[\u@\h \W$(declare -F __git_ps1 &>/dev/null && __git_ps1 " (%s)")]\$ '```
and I even tried https://fedoraproject.org/wiki/Git_quick_reference still does not help.
@yzsatgithub

This comment has been minimized.

Copy link

@yzsatgithub yzsatgithub commented Dec 5, 2019

Thanks man.
So far I'm at:

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \$ "
# gives me:
wayne  ~/dev/lrn (master) $ # my name in green, curr dir in yellow, and branch in green

Still a WIP.

:)

Hi, @wayneseymour. Your answer won't give what you said it would do.
the first \$ in the line export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \$ " should be $, and you have to add more to make the branch green.
You can try this:

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] \[\033[01;32m\]($(git branch 2>/dev/null | grep '^*' | colrm 1 2))\[\033[00m\] \$ 
@wayneseymour

This comment has been minimized.

Copy link

@wayneseymour wayneseymour commented Dec 6, 2019

@yzsatgithub makes sense!

@loneshark99

This comment has been minimized.

Copy link

@loneshark99 loneshark99 commented Dec 22, 2019

PS1='[\033[0;32m][\033[0m\033[0;32m]\u[\033[0;36m] @ [\033[0;36m]\h \w[\033[0;32m]$(__git_ps1)\n[\033[0;32m]└─[\033[0m\033[0;32m] $[\033[0m\033[0;32m] [\033[0m] '

This one is pretty good. I am going to use it. Thank you Sir!

@rohit-mehra

This comment has been minimized.

Copy link

@rohit-mehra rohit-mehra commented Dec 22, 2019

ZSH (minimal - color/no-color + git information)

# Enable colors and change prompt:
autoload -U colors && colors

# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }

# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '[%b]'

# Set up the prompt (with git branch name)
setopt PROMPT_SUBST

# No color
# PROMPT='%n@%m ${PWD/#$HOME/~} ${vcs_info_msg_0_}> '

# Color
PROMPT='%{$fg[yellow]%}%n%{$fg[red]%}@%{$fg[magenta]%}%m%{$fg[green]%} ${PWD/#$HOME/~} %{$fg[magenta]%}${vcs_info_msg_0_}%{$reset_color%}> '
@cppcooper

This comment has been minimized.

Copy link

@cppcooper cppcooper commented Dec 28, 2019

Thanks to @javieitez for the sed. Was able to come up with this.
(echo -n '(' && git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d '\n' && echo -n ')') | sed 's/()//'
^_^

I lug my bash scripts around everywhere, gotta make them work for different environments. So here are some functions in case anybody wants to do similar.

fnexists(){
  declare -f $@ > /dev/null;
  return $?;
}
if ! fnexists __git_ps1
then
    __git_ps1() {
        (echo -n '(' && git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d '\n' && echo  -n ')') | sed 's/()//'
    }
fi
windows() { [[ -n "$WINDIR" ]]; }
haspriv()
{
  if windows;
  then
    net session > /dev/null 2>&1
    if [ $? -eq 0 ]
    then
      return 0; #true
    else
      return 1; #false
    fi
  elif [ "$(whoami)" != "root" ]
  then
    return 1; #false
  else
    return 0; #true
  fi
}

this is how I actually setup my PS1

#esc="\033"
invert="\[\033[7m\]"
blink="\[\033[5m\]"
underlined="\[\033[4m\]"
dim="\[\033[2m\]"
bright="\[\033[1m\]"
clear="\[\033[0m\]"

cmdtime="\033[1;35m" # colors for trap DEBUG, timestamp before command runs
ps1time="\033[35m[\D{%a %T}]$clear" # ps1 timestamp in case I ever need that again
dir="\[\033[34m\]\w$clear"
branch="\[\033[34m\]$bright\`__git_ps1\`$clear"
login="\[\033[33m\]$bright\u@$clear\[\033[33m\]\h"
if haspriv
then
    prompt="\[\033[33m\]#"
else
    prompt="\[\033[33m\]$"
fi                    # $$clear was buggy
prompt="$prompt$clear" 
place="$dir $branch"
#there is a single character unaccounted for, so I counted a space that shouldn't be counted - on the prompt line.
PS1="\[$clear\]\[\n$login $place\n\]$prompt\[ \]"
PS2="> "

Final product looks something like this

josh@Hannah ~/lin-sys (Hannah-linux)
$ echo $PS1
[Fri 23:37:56]
\[\[\033[0m\]\]\[\n\[\033[33m\]\[\033[1m\]\u@\[\033[0m\]\[\033[33m\]\h \[\033[34m\]\w\[\033[0m\] \[\033[34m\]\[\033[1m\]`__git_ps1`\[\033[0m\]\n\]\[\033[33m\]$\[\033[0m\]\[ \]
@rajBopche

This comment has been minimized.

Copy link

@rajBopche rajBopche commented Jan 17, 2020

HELP NEEDED

Guys, I just can't get this thing right,

WHAT I DID (my bash_profile)

image

WHAT WAS THE OUTPUT(my terminal)

image

For some reason, the output displays the entire last line of the bash_profile as it is. As if it never got processed.

System Specs:
image

@mxdpeep

This comment has been minimized.

Copy link

@mxdpeep mxdpeep commented Feb 5, 2020

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\] \[\033[33;1m\]\w\[\033[m\] (\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)) \$ "
#

da BEST!

@ProjectAlice

This comment has been minimized.

Copy link

@ProjectAlice ProjectAlice commented Feb 6, 2020

git-prompt.sh : https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh

source ~/.git-prompt.sh         
_ps1_symbol='\[\e[38;2;0;255;0;48;2;70;70;70m\] \$ \[\e[0m\]\[\e[38;2;70;70;70m\]\[\e[0m\]'
export PS1='\[\e]0;\w\a\]\[\e[38;2;40;40;40;48;2;153;204;255m\] \u\[\e[38;2;255;57;57;48;2;153;204;255m\]  \[\e[0m\]\[\e[38;2;40;40;40;48;2;153;204;255m\]\h \[\e[0m\]\[\e[38;2;153;204;255;48;2;255;150;50m\]\[\e[0m\]\[\e[38;2;40;40;40;48;2;255;150;50m\] \W \[\e[0m\]\[\e[38;2;255;150;50;48;2;70;70;70m\]\[\e[0m\]$(__git_ps1 "\[\e[38;2;0;255;0;48;2;70;70;70m\] %s \[\e[0m\]\[\e[38;2;0;0;0;48;2;70;70;70m\] \[\e[0m\]")'"${_ps1_symbol}"' '
unset _ps1_symbol

Screenshot

@beccahalford

This comment has been minimized.

Copy link

@beccahalford beccahalford commented Feb 20, 2020

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

parse_git_remote () {
git ls-remote --get-url 2> /dev/null | sed "s/git@github.com:/https://github.com//" | sed s/.git$//
}

get_date () {
date "+%H:%M:%S"
}

#export PS1="[[\033[32m]\w[\033[0m]]$(parse_git_branch)\n$(get_date) [\033[1;36m][\033[1;33m]-> [\033[0m]"
can anyone fix this, since updating to zsh its broken and i get the string printed instead of my git branch, user an date/time

@AmosChenYQ

This comment has been minimized.

Copy link

@AmosChenYQ AmosChenYQ commented Feb 24, 2020

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

export PS1="\u@\[\033[32m\]\w\[\033[33m\]\$(git_branch)\[\033[00m\]\$ " 

optional parenthesis 💯

This one seems simple and beautiful

@mindplay-dk

This comment has been minimized.

Copy link

@mindplay-dk mindplay-dk commented Feb 27, 2020

Or build your own with this nice graphical UI! 🤓 ❤️

http://ezprompt.net/

@KamalHadini

This comment has been minimized.

Copy link

@KamalHadini KamalHadini commented Mar 13, 2020

Not working on windows.
It says command not found
Untitled

@nitink66 try this one:
git_branch() {
git branch 2> /dev/null | sed -e '/^[^]/d' -e 's/ (.*)/(\1)/'
}

export PS1="\u@[\033[32m]\w[\033[33m]$(git_branch)[\033[00m]$ "

@sputnick-dev

This comment has been minimized.

Copy link

@sputnick-dev sputnick-dev commented Mar 26, 2020

Stop to re-invent the wheel, git a try to liquidprompt

@strawhatcoder

This comment has been minimized.

Copy link

@strawhatcoder strawhatcoder commented Mar 28, 2020

Following video helped me add __git_ps1 to my .zshrc file.

https://www.youtube.com/watch?v=wku-1nJR_oA

@pierrechtux

This comment has been minimized.

Copy link

@pierrechtux pierrechtux commented Apr 8, 2020

I'll leave this here:
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '

Interesting, thanks.

When I'm putting that in my xterm, what is supposed to be the nice-looking is turning into an awful dotted square. See capture attached.

image

This began to happen to my good old Debian (turned into a Devuan) a little while ago, some characters like ' or - are rendered as such a horrible square, and I can't figure out the reason why.
Any idea?

(Yes, I know I'm a bit off-topic... Blame me.)

@barokurniawan

This comment has been minimized.

Copy link

@barokurniawan barokurniawan commented Apr 22, 2020

I'll leave this here:

PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '

capture_du_2016-03-07_19-13-07

i love this one

@BShah5

This comment has been minimized.

Copy link

@BShah5 BShah5 commented Apr 28, 2020

Thanks, this works well for me!

@darwinys123

This comment has been minimized.

Copy link

@darwinys123 darwinys123 commented May 6, 2020

I'll leave this here:
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '
capture_du_2016-03-07_19-13-07

i love this one

error

i love this one but i gives me that error at top :(

@AmineMcloof

This comment has been minimized.

Copy link

@AmineMcloof AmineMcloof commented May 9, 2020

Windows 10 bash users :
open "bash.bashrc" in "C:\Program Files\Git\etc" with any text editor.
add at the bottom :

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

     export PS1=" \[\e[32m\h\] \[\e[36m\W\] \[\033[33m\]"${parse_git_branch}" \n\[\033[0;32m\] └─ \e[33m\]\[\e[1m\] $ \[\e[0m\] "
@mathiasrw

This comment has been minimized.

Copy link

@mathiasrw mathiasrw commented May 19, 2020

I must say I have gotten addicted to the colours and calmness of

PS1="\n\[\033[0;36m\]\u\[\033[0;31m\]@\[\033[0;32m\]\h \[\033[0;35m\]\$( git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(git:\1) /')\n\[\033[1;33m\]\w\[\033[00m\] \[\033[1;33m\]>\[\033[0;00m\] "

image


Bonus: As its just a one-liner it's easy to put in scripts when you load a new vm

echo PS1="\n\[\033[0;36m\]\u\[\033[0;31m\]@\[\033[0;32m\]\h \[\033[0;35m\]\$( git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(git:\1) /')\n\[\033[1;33m\]\w\[\033[00m\] \[\033[1;33m\]>\[\033[0;00m\] " >> ~.bashrc
@Electromorphous

This comment has been minimized.

Copy link

@Electromorphous Electromorphous commented Jul 30, 2020

export PS1="\e[0;34m[\t] \e[m\e[0;32m\h: \e[m\e[0;33m\w: \e[m\e[0;35m$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\e[m\n$ "

this is what I settled for... you'd probably wanna change the \h for \u to display the username

@cheesits456

This comment has been minimized.

Copy link

@cheesits456 cheesits456 commented Aug 3, 2020

This is my custom prompt I just spent a few hours putting together (total time from start to finish, but not total time spent working on it - I get distracted a lot rip). I have my terminal font set to Nerd Font to get the sweet icons in there. I decided to favor readability over compactness, to make it easier for future me if she ever wants to change it.

# prompt
FMT_BOLD="\e[1m"
FMT_RESET="\e[0m"
FMT_UNBOLD="\e[21m"
FG_BLACK="\e[30m"
FG_BLUE="\e[34m"
FG_CYAN="\e[36m"
FG_GREEN="\e[32m"
FG_MAGENTA="\e[35m"
FG_RED="\e[31m"
FG_WHITE="\e[97m"
BG_BLUE="\e[44m"
BG_GREEN="\e[42m"
BG_MAGENTA="\e[45m"

export PS1=\
"\n ${FG_BLUE}╭─${FG_GREEN}${BG_GREEN} ${FMT_BOLD}${FG_RED}${FG_BLACK}\u${FMT_UNBOLD} ${FG_GREEN}${BG_BLUE}"\
"${FG_BLACK}\w ${FMT_RESET}${FG_BLUE}"\
"\$(git branch 2> /dev/null | grep '^*' | colrm 1 2 | xargs -I BRANCH echo -n \"${BG_MAGENTA}${FG_WHITE} BRANCH ${FMT_RESET}${FG_MAGENTA}\")"\
"\n ${FG_BLUE}╰ ${FG_CYAN}\$ ${FMT_RESET}"

image

@joejoseph00

This comment has been minimized.

Copy link

@joejoseph00 joejoseph00 commented Aug 8, 2020

nice one cheesits456, I installed the nerd font but it looks like some of the fonts aren't rendering correctly, you must have all the nerd fonts installed, I only installed the Ubuntu nerd font.

@cheesits456

This comment has been minimized.

Copy link

@cheesits456 cheesits456 commented Aug 8, 2020

i also only installed the ubuntu font - each nerd font contains exactly the same symbols as each other - they're all just patched versions of standard fonts. as far as the symbols/icons are concerned, every nerd font is identical

@vuongggggg

This comment has been minimized.

Copy link

@vuongggggg vuongggggg commented Aug 16, 2020

function __short_wd_cygwin() {
    num_dirs=3
    newPWD="${PWD/#$HOME/~}"
    if [ $(echo -n $newPWD | awk -F '/' '{print NF}') -gt $num_dirs ]; then
        newPWD=$(echo -n $newPWD | awk -F '/' '{print $1 "/.../" $(NF-1) "/" $(NF)}')
    fi

    echo -n $newPWD
}

function __short_wd_cygpath() {
    num_dirs=3
    newPWD=$(cygpath -C ANSI -w ${PWD/#$HOME/~})
    if [ $(echo -n $newPWD | awk -F '\\' '{print NF}') -gt $num_dirs ]; then
        newPWD=$(echo -n $newPWD | awk -F '\\' '{print $1 "\\...\\" $(NF-1) "\\" $(NF)}')
    fi

    echo -n $newPWD
}

FMT_BOLD="\e[1m"
FMT_RESET="\e[0m"
FMT_UNBOLD="\e[21m"
FG_BLACK="\e[36m"
FG_BLUE="\e[34m"
FG_CYAN="\e[36m"
FG_GREEN="\e[32m"
FG_MAGENTA="\e[35m"
FG_RED="\e[31m"
FG_WHITE="\e[97m"
BG_BLUE="\e[44m"
BG_GREEN="\e[42m"
BG_MAGENTA="\e[45m"

function __current_path() {
    echo -n $(cygpath -C ANSI -w ${PWD})
}

export PS1=\
"\n ${FG_BLUE}${FG_GREEN}${FMT_BOLD}\u${FMT_UNBOLD} @ ${FG_GREEN}\h "\
"${FG_BLACK}\$(__short_wd_cygpath) ${FMT_RESET}${FG_BLUE}"\
"\$(git branch 2> /dev/null | grep '^*' | colrm 1 2 | xargs -I BRANCH echo -n \"${FG_GREEN}BRANCH ${FMT_RESET}${FG_MAGENTA}\")"\
"\n ${FG_BLUE}🙈 ▶ ${FG_CYAN}\$ ${FMT_RESET}"

Here is mine, just collected from above comments and custom a bit with cygpath to make it become similar to windows.

Thanks @vankasteelj and @cheesits456.

image

@payam54

This comment has been minimized.

Copy link

@payam54 payam54 commented Sep 11, 2020

I don't have __git_ps1 in my setup so I combined the solutions from several folks here and made this:

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l |/bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] "

The output:
image

@Nikitos096

This comment has been minimized.

Copy link

@Nikitos096 Nikitos096 commented Sep 12, 2020

PS1="\[\033[38;5;242m\]\u@\h"
PS1+=" \[\033[38;5;87m\]\w"
PS1+='\[\033[38;5;63m\]$(if git rev-parse --git-dir > /dev/null 2>&1; then echo " git("; fi)\[\033[38;5;202m\]$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[38;5;63m\]$(if git rev-parse --git-dir > /dev/null 2>&1; then echo ")"; fi)'
PS1+="\n\[$(tput sgr0)\]└─"
PS1+=" \[\033[38;5;11m\]\$\[$(tput sgr0)\] "
export PS1

image

@cheesits456

This comment has been minimized.

Copy link

@cheesits456 cheesits456 commented Sep 12, 2020

oh nice, I didn't know bash supported the += assignment operator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.