oh-my-zsh

Check current default shell

echo $SHELL

Linux default shell is usually /bin/bash

Install zsh

CentOS:

yum -y install zsh
# or
#dnf -y install zsh
yum -y install util-linux-user

Ubuntu:

sudo apt install zsh

Configure default shell

  • Set default shell for root
sudo chsh -s /bin/zsh
  • Set default shell for specific user
sudo chsh -s /bin/zsh <username>

Install git

We need git environment to either install automatically or manually, run the following command

# CentOS
yum -y instal git
# Ubuntu
sudo apt install git

Install oh-my-zsh

oh-my-zsh is a plug-in/theme manager under the zsh shell.

Automatically install oh-my-zsh

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh...
Cloning into '/root/.oh-my-zsh'...
remote: Enumerating objects: 1158, done.
remote: Counting objects: 100% (1158/1158), done.
remote: Compressing objects: 100% (1127/1127), done.
remote: Total 1158 (delta 20), reused 1059 (delta 15), pack-reused 0
Receiving objects: 100% (1158/1158), 778.08 KiB | 218.00 KiB/s, done.
Resolving deltas: 100% (20/20), done.

Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc.

Time to change your default shell to zsh:
Do you want to change your default shell to zsh? [Y/n] Y
Changing the shell...
Changing shell for root.
Shell changed.
Shell successfully changed to '/usr/bin/zsh'.

         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!


Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugins, themes, and options.

Install oh-my-zsh manually

Download source code

git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh

Copy configuration file

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

ZSH_THEME indicates the current theme (sysin). You can change it to "ys" for example. Other themes should refer to the official wiki.

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/root/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
#ZSH_THEME="robbyrussell"
ZSH_THEME="ys"

Notes: theme-related files are located ~/.oh-my-zsh/themes directory.

Plug-in

Built-in autocompletion

The built-in oh-my-zsh command auto-completion function is as follows:

  • Automatically list directories

    Enter cd and press the tab key, the directory will be listed automatically, and you can switch by pressing tab.

  • Automatic directory name abbreviation completion

    To access the long path of /usr/local/bin, just type cd /u/l/b then press the tab key to autocomplete.

  • Automatic capitalization correction

    To access the Desktop folder, just cd de press the tab key for autocompletion, or just type cat rea for autocorrect completion to view README.md.

  • Auto command completion

    Type kubectl and press the tab key to see available commands.

  • Autocomplete command parameters

    Type kill and press the tab key to automatically display the process id.

Tips:

You can ignore the cd command, enter .. or ... and the current directory name to jump.

zsh-autosuggestions

It suggests commands as you type based on history and completions. Press the → key to accept the suggestion.

Install

git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-autosuggestions

Insert zsh-autosuggestions into the plugins=(git) line in the ~/.zshrc file.

plugins=(
    git
    # other plugins...
    zsh-autosuggestions
)

zsh-syntax-highlighting

This package provides syntax highlighting for the shell zsh. It enables highlighting of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors.

Install

git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Insert zsh-syntax-highlighting into the plugins=(git) line in the ~/.zshrc file.

plugins=(
    git
    # other plugins...
    zsh-syntax-highlighting
)
TOC