DEV Community

loading...
Cover image for Make Your Terminal Phenerminal: Customizing Colors and Prompts

Make Your Terminal Phenerminal: Customizing Colors and Prompts

sidney profile image sidney ・4 min read
Cover illustration by me, Sidney

When I was a kid, opening up Terminal and playing emacs games or watching telnet star wars felt like the ultimate hacker experience. Now that I use the command line for more mundane tasks like navigating my directories and generating Rails apps, I like the interface to be a little more exciting than the simple black-and-white default.

As a total beginner, I didn't know there was such a thing as a framework like Oh My Zsh, which lets you choose from its vast collection of themes– I didn't even know you could use programs other than Terminal as terminal emulators! Here's how I made my vanilla Zsh Terminal pretty in a very simple way.

Terminal Themes and Colors

If you open up Terminal's Preferences panel, you'll be able to choose from or edit themes, or "profiles."

The Terminal preferences window on the Profiles tab.

You could create your own profile from scratch, choosing the ANSI colors by hand, but I wanted my Terminal to take on the color scheme Solarized by Ethan Schoonover. Luckily, you can download a .terminal file from the site that, when opened, creates a new Terminal profile with the Solarized colors.

A whole lot more .terminal files can be found in this repository by lysyi3m– if your computer won't let you open them because they're from an unidentified developer, just right-click and "Open With" Terminal. (Make sure 'display ANSI colors' is checked.)

If you install a Zsh framework like Oh My Zsh, changing themes can be as simple as editing a line in your configuration file.

You know what else is as simple as editing a line in your configuration file?

Putting a Frog in Your Prompt

When I was tipped off that you could customize your command-line prompt, there was one obvious question I had to find out the answer to– "Can I put a frog in it?"

Fortunately, gloriously, the answer is yes (as long as your terminal supports unicode, which it should). And I'm far from the first person to think - of - putting - emojis - in the prompt.

With zsh, you'll want to look for a file in your root directory called zshrc. (It might be a hidden dotfile, which you can show in Finder by doing ⌘ + ⇧ + .) Once inside with the text editor of your choice, your target is the line that contains the default prompt, which in Zsh is something like %m%#.

Looking at a zsh prompt can be intimidating if you don't know how to read it, but all the prompt escapes can be found here in the zsh manual. %m gives the machine's hostname up to the first dot, and %# shows a # only if the shell is running with privileges.

Here's my prompt, step by step:

PS1="%F{green} %2~ 🐸 > %f"
Enter fullscreen mode Exit fullscreen mode
  • %F{color} starts a color, in my case green to match my frog friend
  • %2~ shows a ~ at the home directory, or else the last two folders in your path when you're navigating around
  • 🐸 and >, characters on their own, followed by a space
  • %f ends a color, returning my input to the default blue.

All Together Now

As a final touch, I got rid of that "last login" message by running touch .hushlogin in my root directory. Here's what a new Terminal window looks like, in the Solarized Light profile:

Ahhh.

Ahhh.

More Resources

Armin Briegel at scriptingosx.com does a great job explaining how to customize the zsh prompt, and has a whole book on moving to zsh from bash. I highly recommend looking at his posts on minimal Terminal and rotating background colors, if you really want to get fancy.

Laurie's post, below, outlines a way to get a different emoji depending on whether your last command was successful:

And if you're a command-line beginner like me, it's worth it to make use of aliases to supercharge your experience, as my classmate Anmol writes about here: (just put the aliases into your zshrc file instead of bashrc)

Happy emoji-ing!

Discussion (1)

pic
Editor guide
Collapse
joaocardoso193 profile image