Why switch?

At the beginning of the contact oh-my-zsh is honestly just because of its very beautiful theme, such as powerlevel10k theme; this is really very “Sexy” for a person who is always on the terminal to exercise the left and right hand. Later, with the gradual in-depth use, oh-my-zsh deeply integrated with this integrated plug-in solution and so on did bring great convenience; for example, simple command line search, git, docker, kuebctl and other kinds of plug-ins for quick tips and so on.

However, after using the terminal for a long time, I suddenly realized that the fancy terminal themes like powerlevel10k didn’t suit me; when I gradually switched back to some simple themes and jumped left and right in the directories of big projects like Kubernetes, oh-my-zsh’s extremely slow response time started to show its disadvantages; just in the Git repository directory of Kubernetes, holding down the enter key on the terminal could cause animation…

So when you can’t stand the terminal’s responsiveness, I think it’s time to switch to another one.

Prezto Introduction

Prezto has been rewritten by the author who wanted to achieve a good zsh setup by ensuring all the scripts are making use of zsh syntax. It has a few more steps to install but should only take a few minutes extra. —- John Stevenson

Prezto Installation

Prezto installation can be done as described in the repository documentation

zsh installation

First make sure that zsh is already installed, if not, you need to install it through the package manager of the corresponding system:

 1 2 3 4 5  # macOS(最新版本的 macOS 已经默认安装了 zsh) brew install zsh # Ubuntu apt install zsh -y 

Clone Repository

There are two general cases of cloning in the repository, one default cloning to the "${ZDOTDIR:-$HOME}/.zprezto" directory (standard installation):

 1  git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto" 

Another advanced user may use the XDG_CONFIG_HOME configuration:

 1 2 3 4 5 6 7 8  # 克隆仓库 git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-${XDG_CONFIG_HOME:-$HOME/.config}/zsh}/.zprezto" # 调整 Prezto 的 XDG_CONFIG_HOME 配置 # 该配置需要写入到$HOME/.zshenv 中 export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:=$HOME/.config}" export ZDOTDIR="${ZDOTDIR:=$XDG_CONFIG_HOME/zsh}" source "$ZDOTDIR/.zshenv"  Create a soft connection The Prezto installation is easy to customize, after the main repository is cloned, you just need to softlink the relevant initialization load configuration to the $HOME directory:

 1 2 3 4  setopt EXTENDED_GLOB for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}" done 

However, it should be noted that the above command may have compatibility issues when written directly in some shell scripts, in which case it can be simply handled directly by the command:

 1 2 3 4  for rcfile in $(ls${ZDOTDIR:-$HOME}/.zprezto/runcoms/* | xargs -n 1 basename | grep -v README); do target="${ZDOTDIR:-$HOME}/.${rcfile:t}" ln -s "${ZDOTDIR:-$HOME}/.zprezto/runcoms/${rcfile}" "${target}" done 

At this point, the installation of Prezto is complete and you can log back into the shell to see the results.

Change theme

By default Prezto uses the sorin theme, if you are not satisfied with the default theme you can switch it by using the prompt command:

  1 2 3 4 5 6 7 8 9 10 11  # 列出当前支持的主题 prompt -l # 直接在命令行上展示所有主题样式(预览) prompt -p # 临时试用某个主题 prompt 主题名称 # 保存该主题到配置中(使用) prompt -s 主题名称 

grep highlight

By default Prezto will highlight the results when executing grep, which may be distracting on some terminal topics:

The grep highlighting is turned on in the utility plugin and can be turned off by adding the following configuration to ~/.zpreztorc:

 1  zstyle ':prezto:module:utility:grep' color 'no' 

Command, syntax highlighting

Prezto provides various syntax-highlighting configurations via the syntax-highlighting plugin, enable more auto-highlighting by uncommenting the following configurations:

 1 2 3 4 5 6 7 8 9  # Set syntax highlighters. # By default, only the main highlighter is enabled. zstyle ':prezto:module:syntax-highlighting' highlighters \ 'main' \ 'brackets' \ 'pattern' \ 'line' \ 'cursor' \ 'root' 

Note that the default root highlighting is on and all commands executed by the root user will be highlighted, which may make it difficult to see the commands entered in the theme color scheme.

Custom command highlighting

After enabling pattern highlighting in the syntax-highlighting plugin, you can set some custom command highlighting configurations, such as rm -rf, with the following configuration:

 1 2 3  # Set syntax pattern styles. zstyle ':prezto:module:syntax-highlighting' pattern \ 'rm*-rf*' 'fg=white,bold,bg=red' 

oh-my-zsh is a very useful feature to quickly search the history of commands by using the up and down arrow keys. After switching to Perzto, you will find that the up and down arrow search becomes a fuzzy match for all commands; for example, typing vim and paging up and down will match the history of commands with the word vim in the middle of the command:

To solve this problem, switch the zsh-history-substring-search plugin dependency to the master branch and add the HISTORY_SUBSTRING_SEARCH_PREFIXED variable to the configuration:

 1 2 3 4 5  # 切换 zsh-history-substring-search 到 master 分支 (cd ~/.zprezto/modules/history-substring-search/external && git checkout master) # 在 ~/.zshrc 中增加环境变量配置 export HISTORY_SUBSTRING_SEARCH_PREFIXED=true 

There is also a problem in the history search that the same command will be matched more than once if it appears more than once, so to solve this problem you need to add the following variables:

 1  export HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=true 

Other plug-ins

For more available plugins please refer to the documentation for each plugin in the modules directory, and how to enable and configure them.

For your own convenience, I created a quick initialization script under my init project, and these adjustments above will be done automatically:

 1  curl https://raw.githubusercontent.com/mritd/init/master/prezto/init.sh | bash