The Good (Tweak), the Bad (Mac), and the Ugly (Terminal)
Tags: mac, terminal, bash, git
Published: 2018-02-26 06:50:39

---
title: "The Good (Tweak), the Bad (Mac), and the Ugly (Terminal)"
published: true
tags: mac,terminal,bash,git
canonical_url: https://medium.com/@geraldcroes/the-good-tweak-the-bad-mac-and-the-ugly-terminal-8f18b3c3d687
---

![](https://cdn-images-1.medium.com/max/1024/1*TwaNryU2UWiaCufqOq2RaA.jpeg)

> I’ve switched to Mac … for work …

There, I’ve said it.

It feels like confessing a fault. A confession where forgiveness doesn’t ensue. A confession where what follows is contempt, contempt in my (Linux-minded) colleagues’ eyes. So I’ll just give them a good reason ...

> … and so far I’m enjoying it.

Even though I’m a big Linux fan, I’m used to working with a bunch of applications that are not available there, and the Mac (despite the steep price) appeared as an alternative to the virtual-machines hell. Far from being perfect, it’s a good balance between a Unix system and an end-user general-purpose machine.

However, coming from Linux, the jarring out-of-the-box experience with the terminal was a shock. The default setup is just plain terrible — outdated, no autocompletion, no colors … no fun.

But after a few tweaks I’m feeling at home, and this article is all about sharing configuration options so that people like me will keep enjoying their beloved command lines.

Here is our starting point.

![](https://cdn-images-1.medium.com/max/1024/1*ewtkWxuMfrtVA1d76o5TfA.png)<figcaption>People don’t like the terminal … you don’t say!</figcaption>

### Step 1 — Homebrew

Because there is a life beyond the App Store, your first step on Mac should be to install Homebrew. It’s not mandatory; it just makes your life easier (you decide).

According to [its website](https://brew.sh), Homebrew is the “Missing package manager for Mac.”

In Linux words, it’s our _apt_, _yum_, _dnf_, or _pkg_ (depending on where you come from).

Installing Homebrew is a one-liner:

{% gist https://gist.github.com/geraldcroes/b0395be88de13da286b651f867e39ddc %}

#### Done, but Nothing Has Changed

Exactly, nothing has changed, except that you’ll be able to install, update, and remove the other tools we’ll talk about in a minute.

### Step 2 — Update Bash to Version 4.4

Supposedly because of licensing issues (GPLv2 vs. GPLv3), the bash that comes with our Macs is stuck in 2007 (version 3.2).

Let’s fix this and update to version 4.4 (at the time of this writing).

> brew install bash

Yes, it’s that simple.

#### Configure Bash 4.4 as Your Default Bash

Now that you have the newer version of Bash installed, you need to tell your terminal to use it instead of the default login shell.

Open the terminal preferences and set the “Shells open with” option so that it points to your new best friend, _/usr/local/bin/bash_, which is the location where Homebrew has installed it.

![](https://cdn-images-1.medium.com/max/1024/1*_GwAGVqN-JLoJ5spB2Fy1A.png)

Then, for a reason I have yet to understand, you need to add that same path to your _/etc/shells_ file. If you don’t, you might stumble upon small issues (e.g. I wasn’t able to make my terminal play along with [Alfred](https://www.alfredapp.com)).

{% gist https://gist.github.com/geraldcroes/53fc1d647ed6403b227669e4e8e22a33 %}

Restart your terminal and type _bash --version_ to check that everything works as expected (you can also try to _echo $BASH\_VERSION_).

![](https://cdn-images-1.medium.com/max/1024/1*_Mvs5WCfoCazcbJsDAQZtQ.png)<figcaption>The terminal now has Bash 4.4 by default.</figcaption>

### Step 3 — The Colors of Bash

To steer clear of the dim monochrome corner Apple wants you to stay in, enable the colors.

> _vi ~/.bash\_profile_

{% gist https://gist.github.com/geraldcroes/e56323152f5105261ddaf15df9714e5d %}

Take this new configuration file into account (_source ~/.bash\_profile_) and see for yourself :-)

#### **Before**

![](https://cdn-images-1.medium.com/max/1024/1*GAUIohm0kWeZDoEXQv6bLg.png)<figcaption>Life in green.</figcaption>

#### After

![](https://cdn-images-1.medium.com/max/1024/1*pgaXbl4_XPGdMnNwdX3BTA.png)<figcaption>Not much on this screenshot, except that the colors for directories and regular files are now different.</figcaption>

### Step 4 — Autocomplete Time

It’s time to allow your fingers to rest and let them enjoy the power of the tab key for a bit of auto-completion (that goes beyond file names).

> brew install bash-completion

Now update your _.bash\_profile_ (_vi ~/.bash\_profile_), and add the following line

> [-f /usr/local/etc/bash\_completion] && . /usr/local/etc/bash\_completion

If you need autocompletion for Git, you’ll need to install or update it (the version provided with XCode doesn’t work with the completion).

> brew install git

And as usual, restart your terminal if you want to test it right away.

### Step 5 — May I Ask for a Git Prompt?

If you use Git, the one thing still missing from your now-good-looking terminal is a Git prompt with the state of your repository and the branch you’re on.

Once again, you’re just a single brew command away from the solution.

> brew install bash-git-prompt

To load its configuration at startup, you need to add the following lines into your _.bash\_profile_ file.

> vi ~/.bash\_profile

{% gist https://gist.github.com/geraldcroes/e09e34b7d34a1529089aaeb6796fd8fe#file-bash\_profile %}

You now have a nice Git prompt you can configure to your taste.

#### What It Looks Like in a Non-Git Directory

![](https://cdn-images-1.medium.com/max/1024/1*jfxNxQfykQCIFYbHQmLikg.png)<figcaption>The green tick means that the last command has been successful.</figcaption>

#### What It Looks Like in a Git Directory

![](https://cdn-images-1.medium.com/max/1024/1*9Jf83cAq4hzCdsS_4yCdww.png)

You can see that I’m on the master branch and that everything is synchronized with the distant repository.

#### Tune It a Bit More

The [bash-git-prompt](https://github.com/magicmonty/bash-git-prompt) package comes with multiple configuration options. To test them out, you can create a _~/.git-prompt-colors.sh_ file. For what it’s worth, here is mine below.

{% gist https://gist.github.com/geraldcroes/2f7e7a6161f6455fb24240a39bbff769 %}

![](https://cdn-images-1.medium.com/max/1024/1*EuSYqdXk_RKPMUnvGNFqiQ.png)

### **My Pimped Out Terminal**

With a pinch of transparency and a nice background texture, here is what my own terminal looks like.

![](https://cdn-images-1.medium.com/max/1024/1*aLLO_4RFXaM2VEZI7ZTv1g.png)

I hope you’ve enjoyed the tour and that you have learned a trick or two to make your terminal a better experience.

You can download my configuration [from Github](https://github.com/geraldcroes/macbook-terminal).

If you have some tips you’d like to share with a new Mac user, make sure to add them in the comments section.