MacOS Guide Chapter 2¶
iTerm2 and Zsh
iTerm2¶
iTerm2 is an open source replacement for Apple's Terminal. It's highly customizable and comes with a lot of useful features.
Installation¶
Use Homebrew to download and install:
Text Only | |
---|---|
1 |
|
Customization¶
Colors and Font Settings¶
Here are some suggested settings you can change or set, they are all optional.
- Set hot-key to open and close the terminal to
command + option + i
- Go to profiles -> Default -> Terminal -> Check silence bell to disable the terminal session from making any sound
- Download one of iTerm2 color schemes and then set these to your default profile colors
- Change the cursor text and cursor color to yellow make it more visible
- Change the font to 14pt Source Code Pro Lite. Source Code Pro can be downloaded using Homebrew
brew tap homebrew/cask-fonts && brew install --cask font-source-code-pro
- If you're using BASH instead of ZSH you can add
export CLICOLOR=1
line to your~/.bash_profile
file for nice coloring of listings
MacOS shortcuts ⌘←, ⌘→ and ⌥←, ⌥→¶
You might be familiar with shortcuts to skip a word (⌥) or go to start/end of the line (⌘). iTerm is not set up to work with these shortcuts by default but here's how you set them up:
Open up iTerm2 preferences (⌘ + ,) -> Profiles -> Keys -> Click on +
icon (add new Keyboard shortcut).
shortcut | action | Esc+ |
---|---|---|
⌘← | Send Escape Sequence | OH |
⌘→ | Send Escape Sequence | OF |
⌥← | Send Escape Sequence | b |
⌥→ | Send Escape Sequence | f |
## zsh |
The Z shell (also known as zsh
) is a Unix shell that is built on top of bash
(the default shell for macOS) with additional features. It's recommended to use zsh
over bash
. It's also highly recommended to install a framework with zsh
as it makes dealing with configuration, plugins and themes a lot nicer.
We've also included an env.sh
file where we store our aliases, exports, path changes etc. We put this in a separate file to not pollute our main configuration file too much. This file is found in the bottom of this page.
Install zsh
using Homebrew:
Text Only | |
---|---|
1 |
|
Now you should install a framework, we recommend to use Oh My Zsh or Prezto. Note that you should pick one of them, not use both.
The configuration file for zsh
is called .zshrc
and lives in your home folder (~/.zshrc
).
Oh My Zsh¶
Oh My Zsh is an open source, community-driven framework for managing your zsh
configuration. It comes with a bunch of features out of the box and improves your terminal experience.
Install Oh My Zsh:
Text Only | |
---|---|
1 |
|
The installation script should set zsh
to your default shell, but if it doesn't you can do it manually:
Text Only | |
---|---|
1 |
|
Configuration¶
The out-of-the-box configuration is usable but you probably want to customise it to suit your needs. The Official Wiki contains a lot of useful information if you want to deep dive into what you can do with Oh My Zsh, but we'll cover the basics here.
To apply the changes you make you need to either start new shell instance or run:
Text Only | |
---|---|
1 |
|
Plugins¶
Add plugins to your shell by adding the name of the plugin to the plugin
array in your .zshrc
.
Text Only | |
---|---|
1 |
|
You'll find a list of all plugins on the Oh My Zsh Wiki. Note that adding plugins can cause your shell startup time to increase.
zsh-syntax-highlighting¶
The Syntax Highlighting plugin adds beautiful colors to the commands you are typing.
Clone the zsh-syntax-highlighting plugin’s repo and copy it to the “Oh My ZSH” plugins directory.
Text Only | |
---|---|
1 |
|
zsh-autosuggestions¶
This plugin auto suggests any of the previous commands. Pretty handy! To select the completion, simply press → key.
Clone the zsh-autosuggestions plugin’s repo and copy it to the “Oh My ZSH” plugins directory.
Text Only | |
---|---|
1 |
|
Enforce Changes¶
To apply the changes you make you need to either start new shell instance or run:
Text Only | |
---|---|
1 |
|
my preference:
Bash | |
---|---|
1 2 3 4 5 6 7 |
|
Themes¶
Changing theme is as simple as changing a string in your configuration file. The default theme is robbyrussell
. Just change that value to change theme, and don't forget to apply your changes.
Text Only | |
---|---|
1 |
|
my preference:
powerlevel10k: https://github.com/romkatv/powerlevel10k
You'll find a list of themes with screenshots on the Oh My Zsh Wiki.
Prezto¶
Prezto is a configuration framework for zsh
; it enriches the command line interface environment with sane defaults, aliases, functions, auto completion, and prompt themes.
Install Prezto:
Text Only | |
---|---|
1 |
|
Next create your ~/.zshrc
by running:
Text Only | |
---|---|
1 2 3 4 |
|
For more information on customisation visit the GitHub repository for Prezto.
Modules¶
Add modules to Prezto by editing ~/.zpreztorc
and adding the modules as strings to the list:
Text Only | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
And don't forget to apply your changes by starting a new shell instance.
Themes¶
To list all available themes run:
Text Only | |
---|---|
1 |
|
Then open up your config file (~/.zpreztorc
) and change to the theme you want:
Text Only | |
---|---|
1 |
|
env.sh
¶
To include env.sh
, open ~/.zshrc
and add the following:
Text Only | |
---|---|
1 |
|
This file comes with some pre-defined settings, they are all optional. Please review them before you use them as your configuration. These are just examples to show you what you can customise in your shell.
Text Only | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|