Nowadays many people use a computer without even knowing about the existence of the command line or shell. On the other hand, a large percentage of those who do know about it are intimidated by its monochromatic and unintuitive appearance, and overlook the incredible productivity and usefulness it has, since it allows us to perform all kinds of functions on our computer without having to touch the mouse. For this reason, I have decided to write this quick guide to get the shell ready to start typing, without hurting our eyes.
This guide is designed for macOS users.
Table of content
1. iTerm2 Installation
Since the native macOS terminal restricts us a lot of customization, we will install iTerm2 from this link. If we have homebrew installed on our Mac, we will run:
$ brew cask install iterm2
Once installed, we will see this, more or less:
2. Zsh Installation
Many modern computers come with zsh preinstalled. To check if yours is up to date, run:
$ zsh --version
Make sure the version is 5.0.8 or newer for later steps. If it is an older version, or an error appears, we will proceed with the installation:
With homebrew
$ brew install zsh
Now we need to set zsh as our default shell. To do this, we will need administrator permissions (if you don’t have these, I describe a solution without sudo permissions below). In the different versions of MacOS:
MacOS version | Command |
---|---|
M1 Macs | chsh -s /opt/homebrew/bin/zshc |
Intel Macs (Newer than High Sierra) | chsh -s /usr/local/bin/zsh |
Intel Macs (High Sierra or older) | chsh -s /bin/zsh |
If you do not have administrator permissions, you can use zsh as follows:
iTerm2>Preferences…>Profiles>Default>General>Command>Custom Shell>Route/To/Zsh
3. Oh My Zsh Installation
Oh my zsh is an open source, community-driven framework for managing your zsh configuration. For further info check its repo.
In our new console with zsh, we will run the following code for the Oh My Zsh installation:
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
From now on, our configuration file is located in ~/.zshrc
. If we open it with nano ~/.zshrc
, we will find a line with the code ZSH_THEME= ...
. We will edit it later.
4. Powerlevel10k Installation
Powerlevel10k is a theme for zsh, with which we will be able to customize our terminal, as we will see later. The repository is located at this web, if you want to take a look at it.
To install it, we will execute the following command in the $HOME directory:
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
Now, we must enter the Zsh configuration: nano ~/.zshrc
, and edit the line to ZSH_THEME='powerlevel10k/powerlevel10k'
.
Then, we will have to restart the program. Now, the configuration of the appearance of our new terminal will begin.
5. Powerlevel10k Configuration
The p10k wizard will ask us a few questions, and it is important that we install all the fonts it suggests, or we will encounter errors in the representation of symbols later on.
If you want to change the configuration at any time, just type the following command:
$ p10k configure
This is an example of a fully configured terminal with Powerlevel10k:
6. Extras
From now on, I will start with tools that, while very helpful, are not necessary. Even so, I recommend following this guide to the end to set up a pro shell.
Autosuggestion
This tool will allow us to repeat previous commands without having to rewrite them again. It acts as a plugin, so we will have to install it…
$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
…and configure the plugin. For this, we will go to the same configuration file (nano ~/.zshrc
`), and type:
plugins=(zsh-autosuggestions)
That’s it! Save the file and restart iTerm2, and everything will be working.
Syntax highlighting
Thanks to this plugin, our shell will detect the bash language syntax on our command line, checking if we have typed the instructions correctly. To install it, run (with homebrew):
$ brew install zsh-syntax-highlighting
After installation, we will go to the configuration file, and type zsh-syntax-highlighting
in the plugins section:
Lsd and Bat
These two tools are substitutes for “ls” and “cat”, respectively, making the command much more visually appealing, and representing the information in a more readable way. To do this we will use homebrew with the following command:
brew install lsd bat
Once installed, we can run lsd and bat as two more commands. Here is an example:
Conclusion
In summary, customizing our console can be a somewhat complex process, but as it is something we only have to do once, it is worth it from my point of view. It has relieved me of a lot of headaches searching through endless lines of commands, because although it won’t be able to work for us, it will make it a little more pleasant.