This is the 7th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.

Author: Mintimate

Blog: www.mintimate.cn

Minxml’s Blog, just to share with you

preface

Nowadays, more and more people tend to use ZSH as their terminal Shell instead of bash.

Indeed, Zsh is the modern Shell:

  • Richer command prompts
  • Sharper presentation markup
  • More powerful plug-in support

What is the ZSH

Like bash, ZSH is a command-line interpreter inside a terminal, called a shell for short.

As the name suggests, it’s a shell on the outside of the machine for human-computer interaction. Receives commands from users and other programs and converts them into a language the kernel can understand.

Specifically, its function is that the user enters a command, and the shell immediately interprets and executes one. Not limited to system, language and other concepts, modes of operation and expression. Examples are the CD, wget, curl and mount commands we use.

Traditional shells (such as bash) display monochrome commands and text. ZSH supports not only color fonts, but also command padding:

Instead of entering the full path, ZSH can now automatically fill it by pressing Tab:

Video tutorial

I don’t have any good videos to make recently, so I made a corresponding video for this tutorial:

If you think the tutorial is useful, remember the video coin, like ao ~ : B station video address

How do I install ZSH

By default:

  • MacOS Catalina(MAC10.15) The system starts using ZSH by default. Even macOS High Sierra(MAC10.13) comes with ZSH
  • Linux generally uses bash by default and requires manual installation

So, this directory is mainly how to install ZSH on Linux, Mac users after macOS Catalina can directly jump to the oh-my-zsh configuration.

Older versions of macOS enable ZSH

Older Versions of macOS also come with ZSH, which you can type in the terminal:

cat /etc/shells
Copy the code

The normal content is:

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
Copy the code

/bin/zsh is ZSH. We just need to set ZSH as the terminal default shell, terminal input:

chsh -s /bin/zsh
Copy the code

In this case, press Command+Q to exit the terminal and restart the terminal to use the ZSH terminal.

ZSH Settings are too duplicative, but we can use oh-my-zsh for quick configuration. See oh-my-zsh below.

Linux installation ZSH

ZSH does not come with Linux. You can run the following command to check ZSH:

cat /etc/shells
Copy the code

In normal case, there should be no /bin/zsh:

Install apt-get/yum to install apt-get

If your Linux is based on Debian/Ubuntu, use apt-get as Linux package manager, terminal type:

apt-get install zsh
Copy the code

If you are running Centos/Redhat based Linux, use yum as Linux package manager, terminal type:

yum install zsh
Copy the code

After the installation, run the cat /etc/shells command again.

After that, set it to the default shell and restart the terminal:

chsh -s /bin/zsh
Copy the code

In this case, ZSH is configured successfully;

The ZSH setup is too complicated, but we can use oh-my-zsh to quickly configure it. See oh-my-zsh configuration below.

Oh – my – ZSH

Oh – my – ZSH is what

ZSH was extremely powerful, but was so complicated to configure that at first it was only used by geeks. Later, some geeks developed the oh-my-Zsh plugin to simplify ZSH configuration and make it easier to use.

How to install OH-my-Zsh

Oh-my-zsh is very simple, you can see the project address: github.com/ohmyzsh/ohm… .

The official configuration is very simple, but because the official script of the project is on GitHub, the domestic access may be a little difficult, so we provide three methods to configure.

The official installation

Linux/Mac Open the terminal and enter the script provided by the official:

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

To ensure scripts run smoothly, your Linux/Mac server needs to:

  • Installed in advancegit,curl
  • You can connect to GitHub successfully
  • If you have~/.zshrcFiles, preferably backed up in advance

Script installation

To consider the official method, you need to connect to GitHub; If your device doesn’t have effective access to GitHub. You can use the script I configured:

zsh -c "$(curl -fsSL 'https://host.mintimate.cn/fileHost/download/MTM1NjkzNzI1OTIxMDg0NjIwOQ==')"
Copy the code

To ensure scripts run smoothly, your Linux/Mac server needs to:

  • Installed in advancecurl,unzip
  • If you have~/.zshrcFiles, it is best to back up in advance, otherwise the script automatically changes the original.zshrcFile forzshrcBak

Manual installation

In fact, manually configuring the repeated content is the script CONFIGURATION I wrote:

  1. Download the zip package manually from oh-my-Zsh’s Github home page.
  2. Decompress the zip package and copy it to the ~/. Oh-my-zsh directory.
  3. performcp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrcOr manually copy~/.oh-my-zsh/templates/zshrc.zsh-templateInside the file content to~/.zshrcInside. (If you do not have the ~/.zshrc file, you can create it manually.)
  4. Restart the terminal or terminal inputsource ~/.zshrcMake the configuration take effect

The use of On – my – ZSH

With filling

For example, when we need to use the CD command to go to the Downloads folder, the traditional Bash writing method is:

cd Downloads
Copy the code

With ZSH, we can just type CD or part of the content and press Tab to see the prompt:

Paste automatic escape

With oh-my-zsh, automatic paste escapes are used by default. But it’s easy to go wrong. To do this, if you need to turn off automatic escaping, open the ~/.zshrc file and add the DISABLE_MAGIC_FUNCTIONS=true field:

Tips

ZSH is not only powerful, but also can install more powerful plug-ins, interested in your own exploration. The use of Oh-my-zsh is more than that. You can read the developer documentation: github.com/ohmyzsh/ohm…

Such as:

Oh – my – ZSH in skin

Oh-my-zsh uses robbyrussell by default:

However, I used to use the steeef skin to make changes in the ~/.zshrc file:

I used the Mac document editor to open the file. In fact, I can use the terminal vim command to open it, which is more convenient

After replacing the theme:

Other topics: github.com/ohmyzsh/ohm…

Multiple users use the same ZSH configuration

Bash different users read /etc/bash files as environment configuration files, whereas ZSH, by default, uses configuration files under $HOME. So what if you have multiple users on Linux? Do you configure it every time? In principle, yes, but we can use soft connection to mirror one user’s ZSH configuration to another user’s configuration. Here is an example of mirroring PI user’s ZSH configuration to root user. First, create a soft connection:

Oh -my-zsh /root/.oh-my-zsh sudo ln -s $HOME/Copy the code

After that, the changed PI user is automatically mapped to the root user so that the ZSH configuration on both sides is the same. For oH-my-zsh configuration, you need to enable ZSH_DISABLE_COMPFIX.

# the current PI user is vim ~/.zshrcCopy the code

addZSH_DISABLE_COMPFIX=trueThis data: