Previously, there were several blogs about oh my Zsh and powerlevel 10K color schemes, all of which are flower boxing and embroidered legs, which can make people happy at most. Today, let's introduce some practical configurations that can improve work efficiency.
Plugins
The default login shell has been changed to zsh in the latest macOS operating system. Today, we mainly introduce two zsh plug-ins and some configuration skills to complete the terminal intelligent prompt commands. The protagonists are zsh autosuggestions and zsh syntax highlighting. Presumably, these two software will appear in the configuration list of most Geek Plugins, so there is no need to introduce them, The following two installation and configuration methods are mainly introduced:
Mode 1
Installation:
brew install zsh-autosuggestions zsh-syntax-highlighting
View Details:
brew info zsh-autosuggestions
zsh-autosuggestions: stable 0.7.0 (bottled) Fish-like fast/unobtrusive autosuggestions for zsh https://github.com/zsh-users/zsh-autosuggestions Not installed From: https://mirrors.aliyun.com/homebrew/homebrew-core.git/Formula/zsh-autosuggestions.rb License: MIT ==> Caveats To activate the autosuggestions, add the following at the end of your .zshrc: source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh You will also need to force reload of your .zshrc: source ~/.zshrc
brew info zsh-syntax-highlighting
zsh-syntax-highlighting: stable 0.7.1 (bottled), HEAD Fish shell like syntax highlighting for zsh https://github.com/zsh-users/zsh-syntax-highlighting Not installed From: https://mirrors.aliyun.com/homebrew/homebrew-core.git/Formula/zsh-syntax-highlighting.rb License: BSD-3-Clause ==> Options --HEAD Install HEAD version ==> Caveats To activate the syntax highlighting, add the following at the end of your .zshrc: source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh If you receive "highlighters directory not found" error message, you may need to add the following to your .zshenv: export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/usr/local/share/zsh-syntax-highlighting/highlighters ==> Analytics install: 11,970 (30 days), 29,408 (90 days), 121,898 (365 days) install-on-request: 11,971 (30 days), 29,408 (90 days), 121,845 (365 days) build-error: 0 (30 days)
~/Loading plug-ins in. zshrc
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
After adding the above contents to the configuration file, only the source ~/.zshrc configuration file is required to take effect.
The effect is shown in the figure, which can realize the correct command line color prompt and complete the suggestion information.
Mode II
Installation:
cd ~/.oh-my-zsh/plugins git clone https://github.com/zsh-users/zsh-autosuggestions.git git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
In fact, the github address here has given the github URI when viewing it with the brew info command in the above way. Note that the plug-in can be directly placed in the plugins directory of oh my Zsh.
~/Loading plug-ins in. zshrc
plugins=( git autojump zsh-autosuggestions zsh-syntax-highlighting )
Note that the two installation methods correspond to two different effective methods.
Configuration starts iTerm2 automatically
After the above configuration is completed, you will find that source ~/.zshrc must be executed every time iTerm2 is opened to take effect, and the command cannot be written directly to the ~ /. zshrc file, otherwise infinite loop will be caused.
Therefore, two methods of automatically loading the file are studied:
Method 1
Based on iTerm2 software function
iTerm2-->Preferences-->Profiles-->General-->Login Shell
Add the following configuration: source ~/.zshrc; clear
This configuration item can ensure that the command will be called automatically after starting iTerm2 software every time, and the execution history of the command will be clear ed. However, careful students can find that they can still see the execution process of the command. Anyway, this method is difficult for me to accept, so I don't put on the screenshot, and even think it is a waste of traffic. I believe most people will choose the second scheme, Or if Daniel knows a better plan, he can share it.
Method 2
Relying on zsh shell mechanism
The technical principle will not be introduced too much, and the dry goods will be delivered directly:
vim ~/.zprofile
source ~/.zshrc
Interested students can study the order of loading files in the process of zsh login. Without too much introduction here, they can achieve the purpose.
From then on, we can open iTerm2 and directly enjoy the completion suggestions and syntax highlighting functions!