background

In the Unix kernel operating system, of course, there are now many branches, Linux, OS X are counted. The shell acts as a bridge to the above system kernel instructions. We enter symbols (shell commands) on the keyboard that are easy to remember and recognize. The shell then parses these commands and feeds them back to the kernel to perform a series of operations.

So what does ZSH have to do with shell?

ZSH is also a shell, but it is not the default shell on our system. The default shell on Unix derivatives is bash.

Check the installed shell

Cat /etc/shells Check the existing shells on the Mac. There are six shells

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

CHSH -s /bin/zsh Change the shell type, enter the Mac password to confirm the change, exit the terminal, and log in to the terminal again.

Note: after switching from bash to ZSH, the configuration of environment variables in.bash_profile does not take effect and needs to be reconfigured in ~/.zshrc.

Download iTerm2

The official website: www.iterm2.com/

After the installation is complete, a ZSH file will be displayed in the /bin directory.

The Mac system uses DASH as the terminal by default. You can run the following command to change the default terminal to ZSH:

chsh -s /bin/zsh
Copy the code

The shell color

// Execute git in the user directorycloneCommand,cloneTo a local gitclonehttps://github.com/altercation/solarized / / installation directory: / Users/user/solarized iterm2 - colors - solarizedcd// Execute solarized/osx-terminal.app-colors-solarized/ solarized Dark ansi.terminalCopy the code

In the finder window that opens, double-click Solarized dark. itermcolors and Solarized light. itermcolors to install the Light and Dark colors

iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets

The installationoh my zsh

Oh My Zsh is a further extension of the theme

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
Copy the code

For more information, please refer to oh-my-Zsh’s GitHub page

Configuration ZSH

vi ~/.zshrc
Copy the code
  • Modify the theme

ZSH Subject list: github.com/robbyrussel…

# ZSH_THEME="robbyrussell"
# ZSH_THEME="agnoster"
# Personally like the avit theme
ZSH_THEME="avit" 
Copy the code
  • Set an alias
alias zshconfig='vi ~/.zshrc'
alias vimconfig='vi ~/.vimrc'
alias ll='ls -l'
alias vi='vim'
alias subl='open -a "Sublime Text"'
Copy the code
  • Configure the Meslo font

Meslo LG M Regular for powerline.ttf Meslo LG M Regular for powerline.ttf Meslo LG M Regular for powerline.ttf Then open iTerm2, press CMD +,, open the Preferences configuration screen, and then Profiles -> Text -> Font -> Chanage Font, Select the Meslo LG M Regular for Powerline font.

In addition, VS Code terminal fonts also need to be configured, open VS Code, press CMD +,, open user configuration, add an item

"terminal.integrated.fontFamily": "Meslo LG M for Powerline"
Copy the code
  • Statement highlighting

Special commands and error commands are highlighted. Install using Homebrew

brew install zsh-syntax-highlighting
Copy the code

After the installation is successful, edit the vim ~/.zshrc file and add the following configuration on the last line

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
Copy the code
  • Auto-suggested fill

This function is very practical, can be convenient for us to quickly type the command. To configure, clone the Zsh-AutoSuggestions project to a specified directory:

cd ~
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
Copy the code

Then edit the vim ~/.zshrc file, find the plugins configuration, and add the zsh-autoSuggestions plug-in

plugins=(git osx zsh-autosuggestions)
Copy the code

Note: For highlighting, if it didn’t work, add zsh-syntax-highlighting in plugins and give it a try.

Sometimes, because the color of automatic filling is very similar to the background color, the automatic filling has no effect. We can manually change the color configuration of automatic filling. I changed the color value to 586E75, for example

  • Left and right key jump

Hold down the Option + → OR ← key to switch between the beginning and end of the command. This function does not take effect originally, and you need to manually enable it.

Open iTerm2, press CMD +, to open the Preferences configuration screen, and then Profiles → Keys → Load Preset… → Natural Text Editing.

  • ITerm2 hides user and host names

Sometimes our user name and host name are too long, the terminal display will not look good (as can be seen in the picture above), we can manually remove. Edit the vim ~/.zshrc file to add DEFAULT_USER=”xishuai” as shown in the following example:

  • Enable the command error correction function
# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"
Copy the code
  • The plug-in
  1. git
  2. osx
  3. autojump
plugins=(git osx autojump)
Copy the code