DEV Community

Cover image for Shorten bash shell prompt (and add colors!)
Rei Allen Ramos
Rei Allen Ramos

Posted on

1

Shorten bash shell prompt (and add colors!)

In a previous article, we learned how to append the current git branch in your bash shell:

But if you want to turn your bash shell prompt from this:
Alt Text
to this:
Alt Text
then keep reading 🦄

Shorten bash shell prompt

Fire up your editor and open ~/.bashrc. Look for the block we edited from the previous article:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(show_git_branch)\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(show_git_branch)\$ '
fi
unset color_prompt force_color_prompt

If you want to learn about each and every piece of the script, feel free to head on to the reference section below. The article even talks about how to customize the colors. Otherwise, copy-paste away!

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\[\033[01;33m\]$(show_git_branch)\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@:\W$(show_git_branch)\$ '
fi
unset color_prompt force_color_prompt

As you might have noticed by now, this also changes the color of the git branch part. Enjoy your short and sweet prompt!

Reference:
BASH Shell Change The Color of Shell Prompt on Linux or UNIX

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (1)

Collapse
 
gubaros profile image
Guido Barosio • Edited

(loved the pug)
If for some reason you paste this directly in your terminal, simply type reset to get things back in place.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️