September 15, 2025

Customize Bash prompt and show Git branch

Update on September 17th 2025

In ~/.bashrc, I set PS1 to:

PS1='${debian_chroot:+($debian_chroot)}\[\033[0:36m\]\u\[\033[00m\]@\h \[\033[0:33m\]\w\[\033[00m\] $(__git_ps1 " (%s)") \n\[\033[1:35m\]\$\[\033[00m\] '

About colors

Colors are set with:

\[\033[1:36m\]\

1:36 is the code for cyan.

If a color is set for an element, it applies to the following elements. To “end” the color add

\[\033[00m\] 

right after the element.

Source: https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html

Show Git branch in the prompt

To show Git branch’s name, follow the instructions there: https://raw.githubusercontent.com/git/git/refs/heads/master/contrib/completion/git-prompt.sh

Edit: my lastest bash prompt

PS1='${debian_chroot:+($debian_chroot)}\[\033[1;33m\]\w\[\033[1:30m\] $(__git_ps1 " (%s)") \[\033[0:36m\][\!]\[\033[00m\] \[\033[1:35m\]\$\[\033[00m\] '

looks like:

~  (main) [1995] $

which shows the current directory, the current git branch and the history number.

I often use history number with fc to call a command from history, edit the command, and run it. More details there: https://yctct.com/edit-reexecute


personal computing command-line interface (cli) gnu linux trisquel shell literacy wiki bash

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2025 by yctct is licensed under CC BY-SA 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88