1
头图
When researching terminal tools recently, I found that people's terminals can output various colored texts and various prompts. Even if I use cool Tabby I can't achieve it. OhMyZsh needs to be installed on Linux. Today I will introduce this powerful tool with rich plug-ins!

SpringBoot actual combat e-commerce project mall (50k+star) address: https://github.com/macrozheng/mall

Introduction to OhMyZsh

OhMyZsh is an open source tool that can be used to manage the configuration of Zsh (a type of Linux command interpreter). Using OhMyZsh can make you look like a programmer with 10 years of work experience. OhMyZsh has hundreds of plugins for you to use, as well as various cool themes. OhMyZsh is very popular and there is already 137K+ Star on Github!

Introduction to Zsh

Zsh is mentioned above, which is a kind of Linux command interpreter. The default command interpreter of CentOS is Bash, and sh, csh and tcsh are commonly used. Compared with the default Bash, Zsh is more powerful and has a large number of plug-ins, which can achieve more powerful command completion, command highlighting and other functions.

Install

OhMyZsh is actually a management tool of Zsh, we have to install Zsh before installing OhMyZsh.

Install Zsh

  • There are many ways to install Zsh, it is very convenient to use yum to install, but OhMyZsh officially recommends installing 5.0.8 or higher, let’s first look at the zsh version number in yum;
yum info zsh

  • If your version number is greater than 5.0.8 you can use yum to install, just use the following command, if it is less than you can use the source code to install;
yum -y install zsh

  • First put the downloaded source code package in the specified directory, and then use the following command to unzip and install;
# 安装依赖
yum -y install gcc perl-ExtUtils-MakeMaker
yum -y install ncurses-devel
# 解压
tar xvf zsh-5.8.tar.xz
cd zsh-5.8
# 检查安装环境依赖是否完善
./configure
# 编译并安装
make && make install
  • After the installation is complete, you can use the following command to view the path of Zsh;
whereis zsh

  • Then add the Zsh path to the /etc/shells file, where we can see all the command interpreters supported by the system;
vim /etc/shells 
# 添加内容如下
/usr/local/bin/zsh

  • Finally, check the Zsh version number to check whether Zsh has been installed successfully.
zsh --version

Install OhMyZsh

  • Next, let's install OhMyZsh, directly use the following command to install;
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  • If you are unable to download, you can create a install.sh file first, then copy the content of the file from Github, and then install it using the following command:
# install.sh 地址:https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh
./install.sh
  • After the installation is complete, you will be prompted to modify the default shell used by Linux. Use the following command to view and modify the default shell;
# 查看当前在使用的shell
echo $SHELL
# 也可以使用下面命令自行修改默认shell
chsh -s $(which zsh)

  • After the installation is successful, the configuration file is .zshrc , the installation directory is .oh-my-zsh , and the installation directory structure is as follows.

use

The powerful feature of OhMyZsh lies in its rich plug-ins, and its cool interface lies in its rich themes. Let's introduce them separately.

Theme modification

  • OhMyZsh's themes are very rich, all the themes are in the themes folder;

  • To modify the theme, you only need to modify the ZSH_THEME .zshrc . Below we change the theme to af-magic ;
vim ~/.zshrc
# 修改如下内容
ZSH_THEME="af-magic"
# 刷新配置,每次修改后都需要
source ~/.zshrc
  • After the modification is successful, the theme effect is as follows.

Use plugin

OhMyZsh has more than 300 built-in plug-ins and many third-party plug-ins. It can be seen that the plug-in ecology is very rich. Let's introduce a few useful plug-ins.

OhMyZsh's built-in plug-ins are all in the plugins directory, and as many as 305 are counted.

zsh-syntax-highlighting

Usually when we enter Linux commands, we only know that we have entered a wrong command when we execute it. This plug-in can detect whether the command is wrong in real time.
  • To download the plug-in to the specified directory, use the following command;
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • Then modify the configuration file .zshrc and add the plug-in zsh-syntax-highlighting in plugins;
plugins=(
        git
        zsh-syntax-highlighting
)
  • Next, when you enter the command, there will be a highlight prompt, and the correct command will be displayed in green.

zsh-autosuggestions

Auto-completion plug-in, after entering the command, it will automatically prompt related commands. Use the arrow keys to achieve auto-completion.
  • To download the plug-in to the specified directory, use the following command;
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  • Then modify the configuration file .zshrc and add the plug-in zsh-autosuggestions in plugins;
  • At this time, we enter the command prefix and prompt the command directly, and then press the direction key to realize automatic completion.

zsh-history-substring-search:

The plug-in that can search the command history, use the Ctrl+R to trigger, fuzzy search the command used in the past.
  • To download the plug-in to the specified directory, use the following command;
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
  • Then modify the configuration file .zshrc and add the plug-in zsh-history-substring-search in plugins;
  • Next, we can use the Ctrl+R shortcut key to trigger, and then complete the command search.

docker

It comes with a plug-in, which can realize docker command completion and automatic prompting.
  • As a built-in plug-in, no need to download, directly modify the configuration file .zshrc and add the plug-in docker in plugins;
  • When we enter the command at the beginning of docker, use the Tab key to prompt and automatically complete.

git

It comes with a plug-in and adds a lot of git shortcut commands.
  • Modify the configuration file .zshrc directly and add the plug-in git in plugins;
  • The plug-in provides a lot of shortcuts for Git commands, such as the following commonly used commands;
Shortcut aliasOrder
ggit
gclgit clone
gagit add
gcgit commit
ggpgit push
gglgit pull
gstgit status
gbgit branch
glggit log --stat
  • It is very convenient to use shortcut commands!

z

With its own plug-in, you can quickly jump to the directory of the last cd.
  • Modify the configuration file .zshrc directly, add the plug-in z in plugins, and the final configuration effect is as follows;
plugins=(
        git
        zsh-syntax-highlighting
        zsh-autosuggestions
        zsh-history-substring-search
        docker
        z
)
  • We first switch to the .oh-my-zsh/custom/plugins directory, then switch to another directory, and then directly use the z plug command to switch back.

btop

Our command line terminal is already so cool, and then use the top command to see the running status of the server is a bit out of grade, here is a better tool btop .

Introduction

btop is a server resource monitoring tool that can be used to view the server's CPU, memory, disk, network and process status.

Install

  • After the download is complete, unzip it to the specified directory and install install.sh
# 创建安装目录
mkdir btop
# 解压到安装目录
tar -xvf btop-1.1.2-x86_64-linux-musl.tbz -C btop
cd btop
# 安装
./install.sh

use

  • Btop is very simple to use, you can run it btop
btop --utf-force
  • After the operation is successful, the interface is still very cool, the server resource information is clear at a glance, and I don't want to use the top command anymore;

  • btop also supports mouse interaction, turning a simple command line into a graphical interface, and you can view detailed information by selecting a process;

  • Press ESC key to exit, modify settings or view help;

  • If you want to uninstall, you can use the following command in the installation directory.
make uninstall

Summarize

OhMyZsh is indeed a very good tool. It greatly improves our work efficiency and makes us look more like senior programmers. Btop also makes our command line terminal more cool, and I don't want to use the top command anymore after using it. If you want to make your command line terminal more cool, you might as well try them!

Reference

This article GitHub https://github.com/macrozheng/mall-learning has been included, welcome to Star!

macrozheng
1.1k 声望1.3k 粉丝