Bash & Shell

Make Your Linux Bash Prompt Better — No Zsh or Plugins Required

Abhishek Ghimire · 4 min read
5 views

Make Your Linux Bash Prompt Better — No Zsh or Plugins Required

When working on a Linux server, especially through SSH, the default Bash prompt can feel a little too plain:

root@apps:~/workspace/evaluation/backend#

There is nothing wrong with it, but when you're spending hours in the terminal, a small amount of visual information can make the shell much easier to read.

The good news is that you don't need Zsh, Oh My Zsh, Starship, or any external shell plugins to improve it.

Bash already has everything we need.

In this guide, we'll build a simple Bash prompt that shows:

  • Current username

  • Hostname

  • Current directory

  • Current Git branch

  • Different colors for each part

  • A clean prompt symbol

  • Optional spacing between commands

The result will look like:

root@apps:~/workspace/evaluation/backend (main) #

with each part visually separated by color.


1. Check that you're using Bash

First, check your current shell:

echo $SHELL

You should normally see:

/bin/bash

You can also check the Bash version:

bash --version

No additional shell needs to be installed for this setup.


2. Understanding the Bash prompt

The prompt is controlled primarily by the PS1 environment variable.

You can see your current value with:

echo "$PS1"

A simple Bash prompt might contain:

\u

for the username,

\h

for the hostname, and

\w

for the current working directory.

For example:

PS1='\u@\h:\w\$ '

produces:

root@apps:~/workspace/evaluation/backend#

The \$ is useful because Bash automatically displays:

  • $ for a normal user

  • # for root

So we don't have to hard-code the prompt symbol.


3. Add colors

Bash supports terminal ANSI color sequences.

For example:

\[\e[1;31m\]

starts bold red text, while:

\[\e[0m\]

resets the color.

We can use different colors for different pieces of information.

For example:

PS1='\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;36m\]\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\$ '

This gives us:

root@apps:~/workspace/evaluation/backend#

with:

  • Username → red

  • Hostname → cyan

  • Directory → blue

  • Prompt symbol → default terminal color


4. Show the current Git branch

For development work, knowing which Git branch you're currently on is extremely useful.

Instead of manually typing the branch into the prompt, we can create a small Bash function:

git_branch() {
    git branch --show-current 2>/dev/null
}

Now:

$(git_branch)

will display the current branch.

For example, inside a repository:

main

and outside a repository it will return nothing.


5. Put everything together

Open your Bash configuration:

nano ~/.bashrc

Add the following:

git_branch() {
    git branch --show-current 2>/dev/null
}

PS1='\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;36m\]\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\] \[\e[1;33m\]$(git_branch)\[\e[0m\] \[\e[1;31m\]\$\[\e[0m\] '

Save the file and reload Bash:

source ~/.bashrc

Now, inside a Git repository, you should get something similar to:

root@apps:~/workspace/evaluation/backend main #

6. Make the Git branch cleaner

A small improvement is to display the branch inside parentheses.

Replace the function with:

git_branch() {
    local branch
    branch=$(git branch --show-current 2>/dev/null)
    [ -n "$branch" ] && printf ' (%s)' "$branch"
}

Then use:

PS1='\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;36m\]\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\[\e[1;33m\]$(git_branch)\[\e[0m\] \[\e[1;31m\]\$\[\e[0m\] '

Now the prompt becomes:

root@apps:~/workspace/evaluation/backend (main) #

This is a little easier to scan.


7. Add some breathing room

When running many commands, prompts can start looking crowded:

root@apps:~/workspace/evaluation/backend (main) #
root@apps:~/workspace/evaluation/backend (main) #
root@apps:~/workspace/evaluation/backend (main) #

A simple solution is to put a newline at the beginning of PS1:

PS1='\n\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;36m\]\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\[\e[1;33m\]$(git_branch)\[\e[0m\] \[\e[1;31m\]\$\[\e[0m\] '

Now each new prompt gets a little more vertical space:

root@apps:~/workspace/evaluation/backend (main) #

root@apps:~/workspace/evaluation/backend (main) #

This is particularly comfortable when reading command output on a server.


8. The final configuration

For a simple development server, this is the version I'd use.

Add this to:

~/.bashrc
# Show the current Git branch
git_branch() {
    local branch
    branch=$(git branch --show-current 2>/dev/null)
    [ -n "$branch" ] && printf ' (%s)' "$branch"
}

# Custom Bash prompt
PS1='\n\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;36m\]\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\[\e[1;33m\]$(git_branch)\[\e[0m\] \[\e[1;31m\]\$\[\e[0m\] '

Then reload:

source ~/.bashrc

That's it.

No Zsh.

No Oh My Zsh.

No Starship.

No external plugins.

Just Bash + Git.


9. What each part does

The final prompt is composed of several small pieces.

Username

\u

Example:

root

Hostname

\h

Example:

apps

Current directory

\w

Example:

~/workspace/evaluation/backend

Git branch

$(git_branch)

Example:

(main)

Root/user prompt symbol

\$

Bash automatically chooses:

$

for regular users and:

#

for root.

This means the same configuration works for both regular users and root.


10. Why keep it simple?

There are plenty of tools that can create extremely advanced terminal prompts.

They can show Git status, Python environments, Kubernetes contexts, Docker information, execution times, cloud profiles, and much more.

Those tools can be useful, but they also introduce another layer of configuration.

For a VPS or development server, a lightweight Bash configuration has some advantages:

  • Nothing extra to install

  • Works over SSH

  • Easy to understand

  • Easy to copy to another server

  • Easy to troubleshoot

  • Minimal dependencies

  • Uses Bash's built-in functionality

For many developers, username + hostname + directory + Git branch is already enough information.


Final result

The plain prompt:

root@apps:~/workspace/evaluation/backend#

becomes:

root@apps:~/workspace/evaluation/backend (main) #

with useful color separation and a little breathing room between prompts.

And the entire setup is contained in one familiar file:

~/.bashrc

Sometimes you don't need a new shell.

You just need to make the shell you're already using a little nicer.

Written by

Abhishek Ghimire

Writes here about engineering, technology, and the things worth building.