ITerm2 is the best terminal tool on the MAC. It is easy to think of iTerm2 as a TMUX configured out of the box.

The installationiTerm2

Download and install from the official website.

ITerm features

Featured shortcut keys
  • command+; According to the context call auto – complete window, up and down key selection

  • Full screen command + enter

  • Where’s the cursor? Command +/ (rarely use this, but feel Zsh completion is more useful)

  • Select a path or a word with the mouse to automatically copy

Cursor control
shortcuts instructions
ctrl + a To the beginning of a line
ctrl + e At the end of the line
ctrl + u To delete a line
⌘ + R (CTRL + L) Clear screen, actually roll to a new screen, not clear.
ctrl + r Search command history, which you’re all familiar with
ctrl + d Delete current character
ctrl + h Deletes the previous character
ctrl + w Delete the word before the cursor
ctrl + k Delete to the end of the text
ctrl + t Swap text at the cursor
⌘ + – / + 0 Adjust font size
ctrl + f/b Forward and backward, the equivalent of left and right arrow keys, but obviously faster than moving your hand away and pressing the arrow keys
ctrl + p The previous command is equivalent to the arrow keys
The Windows operating
  • New window: Shift + Command + D (Horizontal) Command + D (vertical)
  • Close the window: Shift + Command + W
  • Previous window: Command + ‘
  • The next window: Command + ~
  • Enter window 1,2,3: option + command + number
TAB page operation
  • New TAB: Command + T
  • Close tabs: Command + W
  • Previous TAB: Command + left arrow key, Shift + Command + [
  • Command + right arrow key, Shitf + Command +]
  • Go to TAB 1,2,3… : Command + Label number
  • Expose Tabs: Option + Command + E (Scatter tabs to the full screen and search all tabs globally)
Panel operation
  • Vertical segmentation: Command + D
  • Horizontal split: Shift + Command + D
  • Previous panel: Command + [
  • Rear panel: Command +]
  • Switch to up/down/Left/right panels: Option + Command + up/down left/Right arrow keys
Other features
  • ITerm2 Preference -> Keys -> Show/hide iTerm2 with a system-wide hotkey
  • To Enter and exit the full screen: Command + Enter
  • Turn background translucency on and off: Command + u
  • The text selection
    • Common click and drag
    • Double-click to select the entire word
    • Three strikes to select the entire row
    • Select a section, hold down Shift, and then click somewhere to select the entire rectangle.
    • Hold Command + Option down to draw a rectangle with the mouse and select text in a similar way to screenshots. Holding Command and clicking on a URL will open that URL in the browser, clicking on a folder will open that folder in the Finder (no more open. (Text files support MacVim, TextMate, and BBEdit. If followed by a colon and a line number, the file will be opened at the line number. Other files cannot be opened by calling the default program.) You can Drag and Drop text pasted to the target.
Place a bookmark

You can save the current position by pressing Command + Shift + M in the current session, and then jump back to it by pressing Command + Shift + J.

Paste the history

Use Command + Shift + H to call out pasted history and support fuzzy search. You can also set the paste history to save on disk (Preferences -> General)

Instant replay

Use Command + Opt + B to enable instant replay and press Esc to exit. Instant playback records the output status of the terminal, allowing you to view the terminal content through time. By default, each session stores up to 4MB of content, which can be changed in Settings (Preferences -> Genernal -> Instant Replay).

Window state

Click Window -> Save Window Arrangement to Save a snapshot of the current Window state, including open Windows, tabs, and panels. Restore Window Arrangement by using Window -> Restore Window Arrangement. You can also set the automatic restoration of the window state when iTerm2 is started in Preferences -> General -> Open Saved Window Arrangement

Make it usable

Install the brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code

After Homebrew is successfully installed, the /usr/local/CELLAR directory is automatically created to store the Homebrew installed programs. At this point you can start using the brew command.

Note: If 400 is returned during installation, you can try to reinstall after a few minutes.

The use of Homebrew

  • Brew Install Specifies the software name, for example, brew Install wget
  • Brew Search Software Name, for example, Brew Search wget
  • Uninstall software: Brew Uninstall Software name, for example, brew Uninstall wget
  • Update all software: Brew Update

Install and switch to ZSH

brew install zsh
Copy the code

Once the installation is complete, set ZSH to the system’s default shell instead of bash.

For permission reasons, the command is executed on the CLI firstopen /etcOpen the folder and find it in the foldershellsFile, copy file to desktop, then open file, add at the end/usr/local/bin/zsh, save after closing. Copy and replace the files in the original directory. Enter the password for verification.

Run the following command on the terminal:

chsh -s /usr/local/bin/zsh
Copy the code

Then restart iTerm2, and ZSH has been configured as the default shell.

The installationoh-my-zsh

Run the following command:

curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
Copy the code

Open the plug-in

~/.oh-my-zsh/custom/plugins/

Open the.zshrc file and modify the plugins

open ~/.zshrc

# Find the plugins configuration item and change it to the following:
plugins=(colored-man-pages zsh_reload git git-flow ruby gem python pip node npm bower sublime)

source ~/.zshrc
Copy the code

The plugin is already enabled

Install other plug-ins

zsh-syntax-highlighting

Highlight your ZSH available commands

$ cd ~/.oh-my-zsh/custom/plugins       Open the plugin folder

$ git clone git://github.com/zsh-users/zsh-syntax-highlighting.git   # Clone plugin project
Copy the code

Open the. ZSHRC file and insert it into plugin

plugins=( [plugins…] zsh-syntax-highlighting)

Source ~/.zshrc # reloads the.zshrc modificationCopy the code

autojump

Autojump is a way to cache all of your visited folder paths by recording your actions in history

brew install autojump
Copy the code

Open the. ZSHRC file and insert it into plugin

plugins=( [plugins…] autojump)

Add the following command to the end of.zshrc

[[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
Copy the code
Source ~/.zshrc # reloads the.zshrc modificationCopy the code

Use j for Autojump, CD to go to the ~/user/github/Youthink folder. Next time you want to go to Yourhink, just type j Youthink or just type part of J Youth

Deleting invalid Paths

J --purge invalid path

Other features

  • Command history

    • Once the correct command is typed and executed, the shell stores a history of the command you typed (in the ~/.zsh_history file) so that you can run the previous command again. You can press arrow keys ↑ and ↓ to view previous commands
    • You can use!!!!! To execute the last command
    • Use Ctrl-R to search for command history
  • Command and file completion (TAB key)

  • Command alias

    • You can simplify command entry by adding alias shortcut=’this is the origin command’ line to.zshrc, which is equivalent to adding an alias
    • To view all command aliases, enter alias in the command line

Some nice Settings

Alias CLS ='clear' alias ll='ls -l' alias la='ls -a' alias grep="grep --color=auto" alias -s HTML ='vim' # Alias -s py=' Vim '# alias -s py=' Vim' # Alias -s js='vim' alias -s c='vim' alias -s Java ='vim' alias -s TXT ='vim' alias -s gz='tar -xzvf' # Alias -s TGZ ='tar -xzvf' alias -s zip='unzip' alias -s bz2='tar -xjvf' alias -s TGZ ='tar -xzvf' alias -s zip='unzip' alias -s bz2='tar -xjvf'Copy the code

The Git plug-in

When you enter a Git folder, you can switch the display mode (but only with the font, as discussed below) :

Common commands

Alias Command
gaa git add –all
gb git branch
gcam git commit -a -m
gcf git config –list
gl git pull
gp git push
gr git remote
gra git remote add
gst git status

Take most of the git command, command content can refer to ~ /. Oh – my – ZSH/plugins/git/git plugin. ZSH

Oh My Zsh provides a set of system aliases to achieve the same functionality. For example, GST as an alias for Git status. The Oh My Zsh plugin is enabled by default, so if you use Oh My Zsh, you have a set of efficient aliases that are universal.

For a complete list, see: github.com/robbyrussel… Or type alias | grep git command

Use skills

  1. Pressing Tab twice will list all the completion lists and directly start to select. You can use CTRL + N/P /f/ B to switch the completion items up, down, and left
  2. More intelligent history command. ZSH supports limited lookups when using or pointing up keys to find history commands. For example, if you type ls and then press the arrow up key, only the used ls command will be found. In this case, the user will continue to search as before, ignoring ls
  3. Intelligent jump, after installing Autojump, ZSH will automatically record the directory you have visited. You can directly jump to the directory by using j directory name, and the directory name supports fuzzy matching and automatic completion. For example, if you have accessed hadove-1.0.0 directory, enter J hado tojump correctly. J –stat can look at your historical path library.
  4. Directory browse and jump: Type D to list the directories you visit in this session. Type the serial number before the list to jump directly.
  5. Enter.. in the current directory. Or… , or simply enter the name of the current directory. You don’t even need to type CD. In cases where you know the path, such as /usr/local/bin, you can type CD /u/l/b and press Complete to type quickly
  6. Wildcard search: ls -l **/*.sh, can recursively display shell files in the current directory, can replace find when a small number of files. Use **/ to recursively search
  7. Adding setopt HIST_IGNORE_DUPS to.zshrc can eliminate duplicate records or be utilizedsort -t ";" -k 2 -u ~/.zsh_history | sort -o ~/.zsh_historyManually remove

Make it look good

The installationPowerline

Powerline is a script written in Python that beautifies the terminal

1. Install Python 2.X

Since Powerline is written in Python, we must ensure that Python is installed on the Mac on which we install Powerline.

$ python -V
Python 2.7.10

#We can check the Python version by typing the following code on the terminal. If this command does not return any message, Python is not installed on your Mac.
Copy the code
2. Install the PIP

There are many ways to install Powerline. You can use a tool like PIP or Git. I recommend PIP.

Since I have not installed PIP yet, I will install it by executing the following command:

$ sudo easy_install pip
#Or execute the following code to install
$ wget https://bootstrap.pypa.io/get-pip.py -O - | python  
Copy the code
3. Check the Powerline

Install Powerline with PIP

$ pip show powerline-status  Check whether Powerline is installed

#If the following information is displayed after the preceding command is executed, the installation is complete. Skip the next step. If there is no response, go to the next step.
Copy the code

Which information

-- Metadata Version: 1.1 Name: powerline-status Version: 2.2 Summary: The ultimate statusline/prompt utility. Home-page: https://github.com/powerline/powerline Author: Kim Silkebaekken Author-email: [email protected] License: MIT Location: / Users/MAC/Library/Python / 2.7 / lib/Python/site which path - packages # is installed to the Requires:
#In my case, my username is MAC
#So will be installed to/Users/MAC/Library/Python / 2.7 / lib/Python/site - packages under the directory
Copy the code
4. Install the Powerline

(I could not install to system directory due to permissions, so I added the –user option to select install to current user directory)

$ pip install --user powerline-status 
Copy the code
  • Configure.bash_profile(if you have already switched bash to ZSH, skip this step and configure.zshrc).

Create and configure the.bash_profile file to automatically run the Powerline script every time the terminal starts up. Create the following file:

cd ~ && l -h

#Type the above command to check if the.bash_profile file exists in the folder. If not, run the following command. If so, skip the next step.Touch.bash_profile # Create. Bash_profile file open. bash_profile # open fileCopy the code
  • Configuration. The ZSHRC
open ~/.zshrc
Copy the code

Simply modify the following code (which is actually the installation path printed above) and copy it to your bash_profile or.zshrc file:

. / Users / / your username/Library/Python / 2.7 / lib/Python/site - packages/powerline/bindings/bash/powerline. Sh

Note the initial ‘.’ and ‘/powerline/… ‘separated by a space.

Source ~/.zshrc # Save and executeCopy the code

There is also likely to be “powerline/bindings/bash /.. /.. /.. /scripts/powerline-config:: No such file or directory “error. The powerline command was not added to the environment variable. You can use soft link to solve the problem:

Add /Users/[username]/Library/Python/2.7/bin to PATH as follows: /Users/[username]/Library/Python/2.7/bin

Export PATH=/Users/[your user name]/Library/Python/2.7/bin:$PATH. / Users / / your username/Library/Python / 2.7 / lib/Python/site - packages/powerline/bindings/bash/powerline. ShCopy the code
Source ~/.zshrc # Save and executeCopy the code
5. Change the theme

To download the Agnoster theme, also in any directory, execute the following command

$ cd ~
$ git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
$ open oh-my-zsh-agnoster-fcamblor/
Copy the code

Open the folder and double-click install. The themes will be installed under ~/.oh-my-zsh/themes

Open ~/.zshrc #.zshrcCopy the code

Find the ZSH_THEME field and change it to: ZSH_THEME=”agnoster”

Source ~/.zshrc # Save and executeCopy the code

6. Install Powerline fonts

Git Clone to download the Powerline font, run the following command in any directory

$ cd ~
$ git clone https://github.com/Lokaltog/powerline-fonts.git
$ cd powerline-fonts/ && ./install.sh
Copy the code

/Users/ MAC /Library/Fonts /Fonts

All Powerline fonts installed to /Users/mac/Library/Fonts
Copy the code

This means that the font library is installed.

ITerm 2Preferences=>Profile=>Text The font I set here is 12pt Meslo LG S DZ Regular for Powerline, you can choose it according to your preference as long as it is Powerline font.

7. Install a color scheme

To download the color scheme, also in any directory, execute the following command

$ cd ~
$ git clone https://github.com/altercation/solarized.git
$ open solarized/iterm2-colors-solarized
Copy the code

Then enter/Users/MAC/solarized/iterm2 – colors – solarized double-click solarized Dark. Itermcolors and solarized Light. Itermcolors Two files are required to import configuration files into iTerm2

Set the Load Presets in the Profile=> Colors TAB in iTerm 2 Settings to the color scheme you just downloaded.

Here we go: