If you spend any time in Terminal on your Mac, it’s worth customizing the look and feel of the application. Here are some of the most interesting ways you can customize Terminal with themes, colorization, and first-run commands.
Tweaking Terminal’s Theme
Terminal has the built-in ability to theme your shell windows, but you’d never know it by looking at the default white screen.
Navigate to “Terminal -> Preferences” from Terminal’s menu bar.
In the Preferences window select the “Profiles” tab. These options will adjust the appearance of new Terminal windows.
Adjustable appearance settings include background and text color, text-rendering options, text size and typeface, cursor type, selection color, and ANSI colors. ANSI colors are used when a Terminal command displays colored output but won’t appear otherwise.
You’ll notice a number of pre-existing profiles in the menu on the left pane. You can choose one of these or click the “+” button at the bottom of the pane to create a new profile. Profiles are the containers for your settings, so you may want to create a personal profile before tweaking anything.
When ready, set your new profile as your default by clicking the “Default” button at the bottom of the profile pane. All new Terminal windows will now open in this profile.
You can also open Terminal windows in a specific profile from “Shell -> New Window,” which allows you to select the profile for the new shell.
Terminal can run specific shell commands when a shell window is open. These can be assigned on a per-profile basis, so different profiles execute different commands.
Open Terminal’s preference window from “Terminal -> Preferences,” and click on the “Shell” tab.
Under “Startup” check the box next to “Run Command,” then type the shell command you want to execute on startup. Leave “Run inside shell” checked below it.
This setting will auto-save to the associated profile and run the next time a shell is opened in that profile. To turn off the startup command, uncheck the box next to “Run command” to disable.
Colorizing Your Prompt
By editing “.bash_profile,” we can colorize the text in your Terminal prompt. For the neophyte, that’s the fixed text that appears when you open a new shell to the left of the text entry cursor.
Open your “.bash_profile” in nano with the command below:
With “.bash_profile” open, we will want to add a new line that starts with:
After the equal sign we will include our ANSI color codes. Your PS1 also needs to contain any escape sequences for variables like user name, host name, current working directory, and so on. For the prompt in the screenshots, I’ve used the colorization rules below:
export PS1="\[\e[38;5;051;48;5;233m\]\u@\h \W $ \[\e[0m\]"
That prompt includes numerical ANSI color codes as well as escape sequences for the user (\u), host (\h), and present working directory (\W). For a detailed explanation of how this gibberish works, reference our post on colorizing your shell prompt in Linux. You will also want a chart of the xterm-256-compatible ANSI color codes.
Colorize and Format Terminal Text
Typed text in Terminal can be formatted via profile settings or directly through typing shell commands.
To attach a text color to a profile, use the text color setting in “Terminal -> Preferences -> Text.”
To colorize text temporarily, use something like the command below:
printf "\e[31mHello World\e[0m\n"
This will have the following result.
Let’s explain what we just did with the above command:
printfis a Terminal command that prints text to the Terminal’s standard output, a.k.a. the command line.
"opens the printf string
\eescapes the non-printing characters which specify the color
[31mis the ANSI color code for red text
Hello Worldis our string literal
\e[0mclears formatting so text after the string literal does not appear colorized
\nprints a new line
"closes the printf string
If you want the text to continue to appear colorized, leave off the
\e[0m . To end formatting, print
\e[0m to standard output with
Any of the ANSI color codes can be used here; see the above-linked guide for more details.
Typed text can be formatted beyond colorization. If you’re an insane person, you can make the text blink!
printf "Normal \e[5mBlink\n"
Change Window Title
By default, Terminal will show the present working directory, active process, and viewport size in your Terminal window’s title bar.
The title bar’s contents can be adjusted in the “Window” tab of Terminal’s preferences.
Open Terminal’s preference window from “Terminal -> Preferences,” and select the “Window” tab.
Adjust the settings near the top to modify the window’s title. You can see the results reflected in any currently-open shells running the profile you’re editing.
These are only the “greatest hits” of Terminal customization. There is much more you can do to customize your Terminal. Explore the Terminal Preferences menu to find more.
If you want to explore Terminal further, you might be interested in the following posts: