For some time now I’ve been using zsh as my default Unix shell, which is an extended Bourne shell with many improvements, including some features from bash, ksh and tcsh. One of my favorite shells is fish shell. It’s easy to set-up and many of the features that I use comes pre-installed, as it is not POSIX supported it has a much readable (fish) syntax for scripting.

Why I switched from fish to zsh, and using Prezto over oh-my-zsh.

The latter can also be a drawback. Many of the bash scripts I work with are written in bash. That means that fish does not support all of the syntax. For that reason I went looking for an alternative and quickly came to zsh (pronounce it as Z shell). Despite the fact that zsh does not support POSIX by default, zsh makes it possible to emulate POSIX.

The most popular zsh framework is Oh-My-Zsh. Oh my zsh gives you a lot of options to set up your zsh environment. I’ve been using Oh-My-Zsh for a while and for most this is a good choice. However, after using Oh-My-Zsh, I found myself not using many of the features that Oh-My-Zsh has to offer.

So I was looking for an alternative. I quickly came to Prezto. Like Oh-My-Zsh, Prezto is a configuration framework for zsh. It comes with auto completion, aliases, function and prompt themes.

A framework is not necessary if you want to add your own custom configurations, however it does make things a lot easier to set up.

I will discuss the following: how to install zsh and Prezto, useful plugins, theming, features such as aliases and custom functions.

My installation will be on macOS, but this will not be much different if you are a Linux user. If you are on Windows it will be slightly different. If you would like to know how to install zsh and Prezto on Windows, let me know in the comments so I can add those steps later.

TLDR;

If you prefer to get started right away, you can download my zsh configuration here.

Installation

If you are using macOS Catalina or higher then you may have heard that they have replaced bash with zsh as default shell.

Run to see what your current shell is

echo $SHELL

If zsh is not installed, you can use Homebrew. Homebrew is a package manager for macOS. For Linux you can use Snapcraft or Flatpak and Chocolatey for windows. Make sure you have a package manager installed before continuing.

brew install zsh

Then set zsh as default shell:

chsh -s /bin/zsh

Zsh uses ~ / 5 startup files. These will be visible after we install Prezto.

$ZDOTDIR/.zshenv
$ZDOTDIR/.zprofile
$ZDOTDIR/.zshrc
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout

From your terminal you can echo $ ZDOTDIR to see what it refers to. By default it refers to $HOME.

The .zshenv is used every time you start zsh. This is for your environment variables like $PATH, $EDITOR, $VISUAL, $PAGER, $LANG.

  1. The .zprofile is an alternative to .zlogin and these two are not intended to be used together.
  2. The .zshrc is where we add our aliases, functions and other customizations. In this tutorial we will mainly discuss the .zshrc.
  3. The .zlogin is started when you log in your shell but after your .zshrc.
  4. The .zlogout is used when you close your shell.

We’ll come back to the .zshrc later, for now we’ll leave it as is. Let’s start by installing Prezto.

git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"

Then copy-paste the following into your terminal:

setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done

After we have installed Prezto you will find a .zpreztorc file in your $HOME folder next to the zsh startup files. Here we edit our Prezto options.

To install plugins in zsh we need a plugin manager, I prefer zplug but feel free to use any of the other plugin managers. Zplug also makes it possible to install Oh-My-Zsh plugins without any hassle.

#bash #zsh #macos #linux #prezto #oh-my-zsh #fish-shell #linux-and-unix

How To Extend Your Terminal Functionality with zsh and Prezto
3.25 GEEK