Customizing the styles and shortcuts of your Mac terminal

As a beginner lady eng, I remember the terror I felt opening my terminal for the first time. It was all white, cold, and indecipherable. Every line of text was blank ink on a white background. Executing my bash commands was easy enough, but it was hard distinguishing my input commands from the terminal’s output. Oy vey.

Enter the magic of .bash_profile!

Hidden inside your Mac’s user directory is a file called .bash_profile. Your .bash_profile contains all the configurations and preferences for your command line and assigns it a user specific environment; i.e. your terminal!

As a programmer, you’re going to be using your terminal a lot. You may find it useful to customize certain text colors, change command line prompts, and add aliases to certain commonly used functions.

.bash_profile uses a language of code called Bash, which stands for Born Again Shell. As a beginner, all you need to know is that Bash is a command language for your Mac’s operating system. So if you open up your .bash_profile, don’t get intimidated! You can customize your terminal styles easily with just a few steps, and without having any previous experience with Bash. Just follow along :)

Editing your .bash_profile

  1. Open your terminal app
  2. Navigate to your root directory using ( cd ~)
  3. Open your .bash_profile in your text editor of choice (I use Atom): (atom .bash_profile)
  4. If you don’t currently have a .bash_profile on your computer, there are many online resources that supply the Bash code for free. Often, programmers will ask for .bash_profiles from other programmers that have terminal styles that they liked, so sharing profiles is common practice.

Here is what my .bash profile looks like on my screen in Atom, and what my terminal looks like as a result. Your .bash_profile might look different, but follow along to learn techniques on how to edit your styles in Bash.

an example of .bash_profile in Atom
What my terminal looks like with my styles from .bash_profile

In my .bash_profile (shown above), I’ve navigated to the section that defines a function called prompt. This is the section where my terminal’s prompt is both defined and styled.

Please note: If you want some more background into how to build your prompt from scratch, go here.

Here are the things I can change in my existing prompt:

  1. Notice “local char = ” This is where I can define what my prompt’s symbol should look like. It can be a heart, a plus, a pound, or even a peach emoji! I chose the half moon emoji, but you can define your prompt’s character as anything your heart desires. Cat emoji anyone?
  2. Notice the area where lots of local colors are defined with their corresponding Bash color codes. These are the colors used in the areas of my prompt. If I want to change the colors of my prompt, I can use the codes found here that correspond to the color I want.
  3. Below my local colors, you should see a line of intense looking Bash code that directly codes the text of my prompt. There is some heavy Bash code here, but don’t be alarmed. If you look, you can see the names of my previously defined local colors! If you decide to change any of your colors, make sure you change those color variables in the text of your prompt. For example, if you change your local variable BLUE to code for PURPLE (with the corresponding Bash code), make sure you change in the prompt text wherever you see $BLUE to $PURPLE.

And now you have a brand new terminal prompt with all of your favorite colors!

Beautiful! Now, what if I absolutely HATE typing a specific input command all the time???

I can also add in some fancy shortcuts to frequently used commands in my .bash_profile. These shortcuts are defined as Aliases. The section could look like this:

Here, I can define a specific Alias for a complex command that could be hard to remember. How cool is that?!

These tips for .bash_profile are just the beginning of the things that you can do with your terminal. As you progress further in your programming journey, you’ll be able to customize this more and perhaps even learn some Bash along the way.

Now, get coding!