Terminal Command Hacks: Adding Color to macOS Terminal
In my last post, I mentioned how aliases help tie my terminal experiences together as I work in both Fedora and macOS. Today, I’ll talk through how you can add color to your macOS terminal which will also help tie in the same experience as Fedora’s terminal which includes this by default. Why does this matter? When working with many directories and files, you’ll sometimes need to see the broader structure by listing the contents of a directory. The color scheme will let you easily identify which items are folders, files, symlinks, etc. Let’s take a look at how this looks in Fedora and then we’ll walk through modifying the macOS terminal to display in a similar manner.
By default, Fedora’s terminal includes a color scheme that makes it easy to identify certain elements at a glance. Here’s what this looks like…
I listed the contents of a directory and I can quickly tell the difference between between the files, folders, and the single symlink here. The folders are blue, the files are the default text color (set to white in my terminal since I have a dark background), and the symlink is turquoise. I can also see that the symlink points to a directory given the color.
In macOS, this isn’t included by default. Here is what the default output looks like for a directory of a similar structure…
You don’t get the same experience at a glance. While this directory doesn’t contain much, it can become a nuisance for larger directories.
In order to add a similar color scheme, you’ll need to modify the same
.bash_profile file that we modified in my previous blog to add our aliases. There are two lines that we need to add to this file.
export CLICOLOR=1 export LSCOLORS=GxFxCxDxBxegedabagaced
Once you’ve edited the
.bash_profile file, close and then reopen terminal. Here is what you now see after the modification…
While the color scheme doesn’t match our Fedora terminal exactly, it still allows you to easily identify the different elements contained within the directory. You can also change the colors set for the different elements by adjusting the
export LSCOLORS=GxFxCxDxBxegedabagaced line. There are online tools, such as https://geoff.greer.fm/lscolors/, that allow you to visually customize how you’d like elements and then produces the code to insert into your `.bash_profile.