Every time I’ve been a tutor I have given a short introduction to the shell, I was asked if I would write a short guide to how my terminal is configured. I won’t touch on how to actually use the terminal since there already exists a bunch of excellent guides out there, here is a short list of the some of them:
- Codecademy A short guide that covers the basics of the command line, it does not require any prior knowledge.
- Learn it the hard way As the name implies it does not hold your hand, personally I think this approach is more fun.
- Over the wire A hard guide, it tasks you with using the terminal to find passwords on servers. It’s challenging but extremely fun and satisfying, if you have patience and some experience I recommend this guide.
1. Step: Install Xcode (Mac only)
Xcode is apple’s development environment it has an IDE and a series of command line utilities that are needed. It’s free and can be installed by opening the terminal app and typing:
It might take a while, so go get some of the beverage of your choice.
2. Step: Getting a package manager
We still need to install several more utilities and the first is a package manager. A package manager is like an “app store” for your shell, it can get programming languages, utilities, and libraries. Each linux distribution comes with a built in package manager, Ubuntu comes with
apt-get, so if you want to install python you simply type:
Apple has not made a package manager, but there exists options for the for mac. Each has their own pros and cons, I prefer homebrew. Here is a quick pros and cons list of the three most popular package managers for the curios.
You can install homebrew by running this command:
Below is some examples of basic homebrew usage
We can use
brew install to get a bunch of terminal utilities, but brew has an extra trick up its sleeve. Homebrew can “tap” repos that provide extra functionality Caskroom is an example of this.
This allows us to install GUI apps from the command line. Instead of searching google for the
.dmg file, installing and cleaning up we can run:
It can be confusing when you should use
brew cask install vs
brew install. A rule of thumb is to use cask if an app has a graphical interface.
MacOS has a built in terminal appropriately named terminal.app, it is decent but I prefer iterm2, it has a dropdown window and is easier to customize. We can use homebrew to install it
Iterm has a bunch of settings for you to customize, open the app’s preferences and peruse the options. I recommend activating a hot key window (You can find the setting under the keys window).
Iterm has an option to load a configuration from an url, If you want my setup you can get set it in this gist. Once Iterm is set up you can access the hot key window with a user defined short cut I use altt.
Step 3: Oh my zsh!
Mac specific part over, welcome back linux people!
Bash is the most common shell, and is most likely what your using now and what you’ll encounter on every SSH connection you’re going to make. I recommend using the awesome oh-my-zsh framework for zsh. To install the shell run the following command:
Enter your password in order to change shell, and enjoy the first step towards an awesome shell. Some of the benefits are of oh-my-zsh are presented in gif form below
One of the down sides with zsh as opposed to bash is that the added complexity can slow down the shell, especially if you are navigating a large git repo. Remember that you can always start a bash shell by typing
bash, use this to test for portability of your scripts and for the rare occasion when zsh is to slow.
To customize and configure oh-my-zsh a dotfile is used. A dotfile is a hidden file, hidden in the sense that you have to type
ls -a to see it, that is read as the first thing when opening a new shell. The file is located in your home directory and is called
.zshrc. The file is just a series of shell commands, here you can place aliases, plugins, themes, and functions. I’m not going to go into two much detail of what all the options mean but i suggest taking a look at the plugins list, the extract and wd plugins are awesome.
There are three main things you can customize:
- Emulator color theme:. These are the colors of you emulator, how you customize them depend on the emulator you’re using. If you’re using iterm some nice themes can be found here
If you’re not using iterm, just google it.
- The shell theme: This is the layout of the terminal. Some themes are complex and gives you a bunch of information such as host name, current directory, git status, virtual environment etc. The list here shows some nice themes you can test the theme out by changing the
themevariable in your
.zshrcfile and reloading the shell with
- The font: Having a nice mono spaced font is essential and most likley what you are used to. A font can also support powerlines which makes themes such as bulletTrain possible.
Follow the installtion guide in the bullet train repo or pick one of the powerline fonts and set the theme to agnoster if you want the theme from above.
Useful terminal utilities
The last thing I would like to show you is a list of clever utilities that makes using the terminal a more pleasant experience.
bat: Can be installed with
brew install batfor mac people or
sudo apt-get install batfor linux peeps. The utility is meant as a
lessreplacement it provides syntax highlighting when outputting to standard our but, degrades gracefully to cat when piped.
tldr: If you type
tldr curlit will show the most common uses for
curlwith a short description. Perfect for when you know the name of a command but don’t want to search through man pages to find the proper usage.
jq: A json formatter that makes dealing with json data in the shell a joy. It has filtering, pretty printing, and is easy to use.
prettier: When you encounter ugly code, fire this off. It formats and cleans javacript and html out of the box, but has official plugins for python.
colurls: A replacement for
lsthat provides a better color scheme, git info, filetype info. It’s a ruby gem, so read the installtion part of its’ readme.
surge: Want to quickly get some info up on a sharable url? Then this is for you.
youtube-dl: Utility to download and convert youtube videos. Good for if you want to grab some videos for offline viewing or download youtube only songs.
fortune: A small joke utility that gives you a fortune, combines perfectly with the two utilities cowsay and lolcat. Install all three and place the command
fortune -os | cowsay | lolcatat the bottom of your
.zshrcfor maximum dankness.
trash: A mac specific utility that can be installed with
brew install trash. If you have ever mistakenly run
rmon a file, you know that
rmremoves the file immediately. This utility as the name suggests moves it to the trash instead. You can alias it to
alias rm="trash"and future you will thank you some day.
That’s it, Enjoy your new maxed out terminal! If you have questions or run into problems write a comment below, and I might get back to you.