6  The Terminal

If you want to adjust the system settings on your laptop or navigate from directory to directory, you can click through a file tree or open up your preferences pane.

Usually, there are no graphical user interafaces (GUIs) at all. On a server, interaction is via the command line – an all-text interface where you type commands.

Once you feel comfortable using the command line on a server, you’ll probably find that there are many things that will get easier for you locally as well!

This chapter is all about the terminal itself – by the end of the chapter, you’ll understand what the terminal is, how to get it open on your machine, and how to customize it to your liking.

6.1 What makes up the command line?

It is possible to spend a lotof time customizing your terminal to be exactly what you like. Some might argue it wouldn’t be the best use of your time to do so.

Such people are no fun, and having a terminal that’s super customized to what you like is great. Plus you get to feel like a real hacker.

One of the confusing things about customizing your command line is understanding what program you’re actually interacting with and where it’s customized. So here’s a little intro.

There are three programs that sit on top of each other when you interact with the command line – the terminal, the shell, and the operating system.

The terminal is the visual program where you’ll type in commands. The terminal program you use will dictate the colors and themes available for the window, how tabs and panes work, and the keyboard shortcuts you’ll use to manage them.

The shell is the program you’re interacting with as you’re typing in commands. It’s what matches the words you type to actual commands or programs on your system. Depending on which shell you choose, you’ll get different options for autocompletion, options for plugins for things like git, and coloring and theming of the actual text in your terminal.

There is some overlap of things you can customize via the terminal vs the shell, so mix and match to your heart’s content.

Lastly, the operating system is what actually runs the commands you’re typing in. So the set of commands available to you will differ by whether you’re using Windows or Mac or Linux.

graph LR
    A[A Human] --> |Types| B[Commands]
    A --> |Opens| E
    E[Terminal] --> |Opens| C
    C[Shell] --> |Dispatches| B
    D[Operating System] --> |Defines the set of| B
    D[Operating System] --> |Runs| B

In the next few sections of this chapter, we’ll get into how to set up your terminal and shell so that it looks and behaves exactly the way you want.

Note

I haven’t used a Windows machine in many years. I’ve collected some recommendations here, but I can’t personally vouch for them the way I can my Mac recommendations.

6.2 Choose your terminal

If you’re using a Mac, you can use the built-in terminal app, conveniently called Terminal. It’s fine.

If you’re going to be using your terminal more than occasionally, I’d recommend downloading and switching to the the free iTerm2, which adds a bunch of niceties like better theming and multiple tabs.

If you’re using Windows, there are a variety of alternative terminals you can try, but the built-in terminal is the favorite of many users. Experiment if you like, but feel free to stick with the default.

6.3 Choosing and configuring your shell

The default shell for MacOS (and Linux) is called bash. It’s pretty great shell. There’s nothing to really replace bash, but there are bash alternatives that extend bash in various ways.

The most popular bash alternatives include zsh, Ksh, and Fish. If you don’t already have a favorite, I recommend zsh.1

It has a few advantages over bash out of the box, like better autocompletion. It also has a huge ecosystem of themes and plugins that can make your shell way prettier and more functional. There are plugins that do everything from displaying your git status on the command line to controlling your Spotify playlist.

There are two popular plugin managers for zsh – OhMyZsh and Prezto. I prefer and recommend Prezto, but the choice is really up to you.

I’m not going to go through the steps of installing these tools – there are numerous online walkthroughs and guides that you can google.

But it is a little confusing to know what to customize where, so here’s the high level overview if you’ve installed iTerm2, zsh, and prezto. You’ll customize the look of the window and the tab behavior in the iTerm2 preferences and customize the text theme and plugins via prezto. You can mostly skip any customization of zsh in the .zshrc since you’ll be doing that in Prezto.

Windows comes with two shells built in, the Command shell (cmd) and the PowerShell.

The command shell is older and has been superseded by PowerShell. If you’re just getting started, you absolutely should just work with PowerShell. If you’ve been using Command shell on a Windows machine for a long time, most Command shell command work in PowerShell, so it may be worth switching over.

Once you’ve installed PowerShell, many people like customizing it with Oh My Posh.

6.4 Comprehension Questions

  1. Draw a mental map that includes the following: terminal, shell, operating system, my laptop

  1. zsh is pronounced by just speaking the letters aloud. Some people say it zeesh, but they’re not writing this book, are they?↩︎