Today I learned… that your Mac terminal bash prompt can be customized and enhanced well beyond its basic boring default.
A full tour of bash customizations is outside the scope of this post, but I do want to share the simple customizations I use on my own bash prompt.
My prompt displays my username, the current directory’s file path, and the git branch I’m currently in.
To make your bash prompt do this, open your .bashrc file.
$ open ~/.bashrc
.bashrc is a shell script that bash runs when you open bash. This example modifies PS1 (the user prompt). To make yours look like mine, add this to the bottom of your .bashrc file (the # comments are optional).
Save the file, return to your terminal and type source ~/.bashrc to apply the changes.
$ source ~/.bashrc
More bash customizations
That’s just the tip of the iceberg, though, and chances are, there’s more you will want to do to your bash prompt.
Here are two articles I found helpful.
- This IBM Developer Works post on customizing bash includes a handy sequence guide and an explanation of how colors work in bash.
- Martin Fitzpatrick has a great guide to customizing terminal on Mac that I adapted for my own prompt customizations, plus helpful explanations of how this stuff works.
- What is the purpose of .bashrc and how does it work?