Terminal Optimization — Plugin Recommendations

This article is transcoded by 简悦 SimpRead, original address zhuanlan.zhihu.com

1. Install oh my zsh

  1. What is zsh?
    Zsh is a powerful virtual terminal, serving as both a system virtual terminal and an interactive interpreter for a scripting language.
  2. How to check if zsh is installed?
  • Enter in the terminal:
zsh --version
  • My output:
zsh 5.7.1 (x86_64-apple-darwin19.0)

This indicates that I have already installed zsh.

  1. oh my zsh
    ① Installation
    You can install via two methods: curl or wget, with one command.
  • curl installation
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  • wget installation
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

② Simple configuration
Set a fixed theme

  • In the terminal, enter: open ~/.zshrc
  • Find ZSH_THEME="robbyrussell", here the default theme robbyrussell is set. To change the theme, use this format: ZSH_THEME="theme_name"
  • Save the file and reopen the terminal

Set a random theme

  • In the terminal, enter: open ~/.zshrc
  • Set the theme as: ZSH_THEME="random"
  • This way, each time you open the terminal, the theme is random.
  • Example: next time you open the terminal, it will output a message like [oh-my-zsh] Random theme 'xiong-chiamiov' loaded, where ‘xiong-chiamiov’ is the theme name. If you like this theme, you can set it in your .zshrc.

View theme names
oh my zsh comes with some default themes stored in the ~/.oh-my-zsh/themes directory. We can view these themes:

cd ~/.oh-my-zsh/themes && ls

③ Uninstall oh my zsh

uninstall_oh_my_zsh

④ Solution to accidentally disabling the automatic update prompt of oh my zsh

upgrade_oh_my_zsh

2. Install autojump
Plugin function: allows quick directory jumping. Just type j + directory name to go directly to the directory, no need to frequently use cd!

  1. Installation steps
  • Enter in the terminal:
$ brew install autojump
  • Output:

  • According to the prompt, add the following in the ~/.zshrc file:
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
  • Use the source command to update the configuration file:
source ~/.zshrc
  • Now you can use the j command to quickly jump to target directories based on your cd history without repeatedly typing cd~

3. Install zsh-syntax-highlighting
Plugin function: this package provides syntax highlighting for the shell zsh. It highlights commands entered at the zsh prompt in the interactive terminal. This helps check commands before execution, especially for catching syntax errors.
Example: if the command you type does not exist, it shows as red; otherwise, it turns green.

  1. Documentation
  • 《zsh-syntax-highlighting》
  1. Installation steps
  • Enter in the terminal:
$ brew install zsh-syntax-highlighting
  • Output:

Add to ~/.zshrc file:

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  • Use the source command to update the configuration file:
source ~/.zshrc
  1. Install zsh-autosuggestion
    Plugin function: provides command autosuggestions (grey part) while typing; press Tab key (→ ) to complete.

  2. Documentation:

  • 《zsh-autosuggestions》
  1. Installation steps
  • Enter in the terminal:
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
  • Add to the ~/.zshrc file:
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
  • Use the source command to update the configuration file:
source ~/.zshrc