Zsh: The Efficiency Powerhouse for Linux

For developers who use Linux regularly, the shell is one of the most frequently used programs. It acts as a bridge between developers and the Linux system, allowing us to perform complex operations with simple commands.

Bash is the default shell on Linux, while Zsh is a more user-friendly shell that is fully compatible with Bash. Using Zsh is as satisfying as scratching an itch, and it can greatly boost your efficiency when working with Linux.


Steps

1. Installing Zsh

On Debian-based Linux distributions, install Zsh with the following command; other Linux distributions are similar:

1
apt install zsh

2. Installing Oh My Zsh

The default Zsh configuration is a bit tedious, so a user named robbyrussell created a configuration framework Oh My Zsh on GitHub. It is by far the most popular Zsh configuration.

You can install it using either curl or wget. During installation, you will be asked whether to switch your default shell to zsh — enter y to accept:

  • Install with curl

    • GitHub:
    1
    
    sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
    
    • Gitee (domestic mirror)
    1
    
    sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
    
  • Install with wget

    • GitHub:
    1
    
    sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
    
    • Gitee (domestic mirror)
    1
    
    sh -c "$(wget -O- https://gitee.com/pocmon/mirrors/raw/master/tools/install.sh)"
    

3. Setting the Theme

Run the following command to open and edit the Oh My Zsh configuration file:

1
nano ~/.zshrc

The ZSH_THEME="robbyrussell" parameter controls the theme; change it to random to use a random theme.

Every time you open the terminal, you will see output like the following; note down any theme you like:

1
[oh-my-zsh] Random theme '<theme name>' loaded

4. Other Oh My Zsh Operations

  • Uninstall:
1
2
uninstall_oh_my_zsh
Are you sure you want to remove Oh My Zsh? [y/N] 
  • Update:
1
upgrade_oh_my_zsh

5. Zsh Quick Start

Use the following command to open the configuration file, find the plugins parameter, and enter the plugins you want to enable inside the parentheses, separated by spaces:

1
2
3
4
nano ~/.zshrc

# The following is my configuration
plugins=(git z zsh-autosuggestions zsh-syntax-highlighting )

After enabling the plugins, refresh the shell with the following command:

1
source ~/.zshrc

Here is what these plugins do:

  • git: No configuration needed; it is enabled by default. It lets you enter git commands using shorthand aliases. Use the following command to view all the aliases:
1
cat ~/.oh-my-zsh/plugins/git/git.plugin.zsh
  • Z: No configuration needed; it is enabled by default. It lets you quickly jump to directories you have visited before; just use z directory to jump there directly.

  • zsh-syntax-highlighting: Highlights your command input — correct syntax is shown in green and syntax errors in red. You need to install it yourself; the install command is as follows:

1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • zsh-autosuggestions: Finds prefix-matching entries from your command history; press the right arrow key ➡ to complete them quickly. It is especially handy. You need to install it yourself; the install command is as follows:
1
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

References