Supercharge Your Command Prompt with Zsh and Oh My Zsh


Unlock the full power of your Linux or macOS terminal with Zsh and Oh My Zsh, letting you transform your command line with smart autocompletion, customizable themes, and powerful plugins. Boost productivity and streamline your workflow with this dynamic duo.




What Is Oh My Zsh?

Normally, your Linux or macOS terminal uses Bash by default, but there are plenty of other command shells to choose from. While Bash is fine and most people don’t think twice about it, Z Shell (or Zsh) improves upon Bash in many ways. Oh My Zsh or OMZ goes even further by simplifying Zsh configuration and automating tasks, while providing a thriving support community.

Install Zsh and Oh My Zsh

To install OMZ, you need to execute one simple command, but to do so you need to install Zsh and Git first. Here’s how to set it all up across different Linux systems and macOS. If you already have Zsh and Git installed, you can skip to the OMZ install command.

Ubuntu/Debian

sudo apt update

sudo apt install zsh git -y

Install OMZ.

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Fedora

sudo dnf install zsh git -y 

Install OMZ.


sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Arch Linux

sudo pacman -S zsh git --noconfirm 

Install OMZ.

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

macOS

You can install OMZ on macOS but you first need to install Homebrew (brew) first. Brew is a package manager similar to apt, dnf, and pacman, which allows you to install stuff on Mac just like you would on a Linux distribution.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

Now you can install Zsh and Git.

brew install zsh git 

Install OMZ.

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

As it installs, OMZ should ask you to switch your default shell to Zsh (you can always switch back to Bash later) and then automatically restart your prompt.


The oh my zsh successfull installation screen.-1

Basic Customizations

The default Zsh configuration file (.zshrc) is pretty extensive but its mostly stuff you’ll never need and a lot of commented text.

The default .zshrc file with ALL the configuration options.

To make things simple, let’s start over with a new configuration file and some very basic options. First, back up your existing .zshrc file.

mv ~/.zhsrc ~/.zshrc_backup

Using your preferred text editor (we’re using vim, but you can use nano, pico, or whatever you prefer), create a new .zshrc file.


vim ~/.zshrc

Next, type or paste the following:


export ZSH="$HOME/.oh-my-zsh"


ZSH_THEME="bira"


plugins=(git)


source $ZSH/oh-my-zsh.sh


export EDITOR='vim'

Save your new .zshrc file and restart your terminal or type zsh.

The zsh prompt with the bira theme and the git plugin enabled.

More Customizations

Why stop here? There’s so much more you can do to really trick out your command prompt!

More Theme Options

As we pointed out, assigning a new theme is as simple as specifying it in the .zshrc. If you don’t know what theme you want to use, or you want OMZ to surprise you, you can set ZSH_THEME=”random”. Then, every time you open your terminal or type zsh, OMZ will load a different theme.

Setting the theme to %22random%22 does just what you might think it does.-1


If you find a handful of themes you like, and you want to load them randomly, then add the following lines.

ZSH-THEME="random"
ZSH_THEME_RANDOM_CANDIDATES=("themes" "you" "like")

If you don’t know what theme you want, you can check out the full list of themes that every Oh My Zsh installation includes.

Install More Plugins

The git plugin is the basic go-to plugin that every OMZ configuration should have, but there are many others that you can try. Here are four more that you might want to know about.

Zsh-Autosuggestions: This suggests commands as you type, which are based on your history and the commands you use the most. When command you want appears, you can enter the right arrow to complete it.

To install this plugin, enter the following command:

git clone https:
Autosuggestions provides help with completing previously-used commands.


Zsh-Syntax-Highlighting and Zsh-Fast-Syntax-Highlighting: These plugins highlight commands as you type, using colors to indicate valid syntax and errors. To install these plugins:

git clone https:
git clone https: 

While these plugins basically do the same thing, Zsh-Fast-Syntax-Highlighting is designed to be faster in complex or highly customized environments. If in doubt, choose Zsh-Syntax-Highlighting over Zsh-Fast-Syntax-Highlighting for its stability and maturity, and broader compatibility with various Zsh setups.

Zsh-Autocomplete: This plugin enhances tab completion (enter Tab to complete a command) by providing a dropdown selection of commands including flags and directory locations (if you use the cd command). To install this plugin:

git clone --depth 1 -- https:
Autocomplete helps by suggesting commands and directory locations.


Whether you install one or all of these plugins, you’ll need to enable them in your .zshrc.

plugins=(git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete)

Then save the file, exit the editor, and restart your terminal.

Other Useful Options

Here are just a few more options you might consider when creating your custom .zshrc.

Modify History Behavior

You can configure your command prompt to handle and display command history differently. For example, these following options configure Zsh history by setting the log file to ~/.zsh_history, limiting history size to 10,000 commands, and ensuring duplicates and commands starting with a space are ignored, with new commands appended rather than overwriting the file.

HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt append_history
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_expire_dups_first

Case-insensitive Tab Completion

You can enable case-insensitive tab completion, so you can type commands and complete them with TAB without worrying about the case.

setopt nocaseglob 

setopt nocasematch


Autocorrection

Some people don’t like typo autocorrection, and some do. If you’re part of the latter, you can enable autocorrection.

setopt correct

Removing Oh My Zsh

If you decide that OMZ isn’t for you, you can remove it, and even switch your shell prompt back to bash.

First, revert your shell back to bash.

chsh -s $(which bash)

Remove Oh My Zsh and rename the .zshrc file.

rm -rf ~/.oh-my-zsh

mv ~/.zshrc ~/.zshrc_backup

If you prefer to just get rid of everything altogether, then you can remove the .zshrc file.

rm ~/.zshrc


Congratulations on successfully installing and configuring Oh My Zsh on your system! This is a huge step towards enhancing your terminal experience and boosting your productivity. Oh My Zsh unlocks a wide variety of plugins, themes, and other smart customizations that make your command line more efficient and enjoyable. Hopefully, you now feel confident exploring more plugins, tweaking your configuration, and making your terminal your own!




Source link

Previous articleThis Lenovo ThinkPad laptop is usually over $2,000 — today it’s $994