More elegant use of the command line



If a worker wants to do a good job, he must sharpen his tools first. By arming his command-line tools, he can use the command line more elegantly, which can make the work more efficient and interesting. This article will introduce the following aspects of command line skills and tools

CLI one click call in and out

Iterm2 is a completely free terminal tool for MacOS, which can open the hotkey window to achieve the effect of one click call in and out

The results are as follows:


The detailed settings are as follows:

1. First, make the following settings

preferences > Keys > HotKey > Create a Dedicated Hotkey Window...


2. Next, set the hotkey and selectAnimate showing and hidingandFloating windowThese two options



Bash is the default shell for Linux and OS X systems.oh my zshIt’s an enhanced shell

If it’s Mac OS, you should bring it by defaultzshYes, it can be confirmed before installation

cat /etc/shells

# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.


You can view the current environment’sshell

echo $SHELL

You can use the following commandshellSwitch. Especially, switchshellAfter that, restart the CLI to take effect

Chsh - S / bin / bash ා switch Bash
Chsh - S / bin / Zsh ා switch Zsh

Next, start the installationoh-my-zshPlease pay special attention to that you cannot use the address of the official website for installation, otherwise you will be prompted

Failed to connect to port 443: Connection refused

Instead, install it at the following address

$ sh -c "$(curl -fsSL"

After the installation is completed, you will be prompted whether tozshSet as default shell, selectY

Time to change your default shell to zsh:
Do you want to change your default shell to zsh? [Y/n] y
Changing the shell...
Changing shell for root.
Shell successfully changed to '/bin/zsh'.

         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/              now installed!

Please look over the ~/.zshrc file to select plugins, themes, and options.

p.s. Follow us on

p.p.s. Get stickers, shirts, and coffee mugs at

Here is a brief introductionoh-my-zshThe advantages of

1. The topic prompt changes from user name and host name to the name of the current directory

2. Press tab to complete, you can not only complete the command, but also complete options, parameters, files, etc

3. The jump path can omit the CD command and match the first character of the path


After pressing the tab key, the following path will be automatically completed


4. Enter D directly under the current directory to display the list of historical access directories (the last 20), and add a numerical index on the left

$ d
0   ~/Desktop/md/blog
1   ~/Desktop/md
2   ~/Desktop
3   ~

Alias configuration

Using git alias configuration can make git experience easier

It can be done throughgit configCommand for commandgit branchSet an alias

$ git config --global alias.b branch

This means that when you want to inputgit branchOnly input is requiredgit bJust fine

The simpler way is to edit directly~/.gitconfigFile, can achieve the same effect

b = branch

But if you just want to inputgbYou want to achieve itgit branchFor the same effect, you need to use the alias function of Linux

actually,zshThe GIT plug-in has been set by default. The file path is as follows


Here are some common configurations

alias g='git'
alias ga='git add'
alias gb='git branch'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gcam='git commit -a -m'
alias gcb='git checkout -b'
alias gcmsg='git commit -m'
alias gco='git checkout'
alias gd='git diff'
alias gl='git pull'
alias glog='git log --oneline --decorate --graph'
alias gloga='git log --oneline --decorate --graph --all'
alias gp='git push'
alias gsb='git status -sb'
alias gst='git status'

usegstThe effect is as follows

$ gst
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD ..." to unstage)

    new file:
    new file:   t.html


Brew is also calledhomebrew, is a software package management tool on MAC, which can easily install or uninstall software in MAC

Here ishomebrewCommon commands for

Brew install Git
Brew uninstall WGet
Brew list ා lists the installed software

Plug in Recommendation

Here are some plug-in recommendations. After the plug-in is installed, it needs to be opened~/.zshrc, foundplugins=Then write the name of the plug-in you need. As long as you modify this file, use thesource ~/.zshrcTo update the configuration

Quick jump

autojumpThe plug-in realizes the quick jump between directories. Which directory do you want to go to directlyJ + directory nameNo more frequentcd

useautojumpCommand, or use a short commandjTo jump to the specified directory. Note that only opened directory plug-ins will record. Therefore, the longer it is used, the more intelligent the plug-in will be

j directoryName


The installation is as follows:

brew install autojump

And then in the.zshrcAdd the following statement to the file

[[ -s `brew --prefix`/etc/ ]] && . `brew --prefix`/etc/

Command prompt

usezsh-autosuggestionsThe plug-in can prompt automatic completion (gray part) when entering command, and then press the right key of keyboard direction to complete


The installation is as follows:

cd ~/.oh-my-zsh/custom/plugins/
sudo git clone

Syntax highlighting

usezsh-syntax-highlightingPlug in, the daily command will be highlighted, and the command error will be displayed in red


The installation is as follows:

cd ~/.oh-my-zsh/custom/plugins/
sudo git clone

Order correction

usethefuckPlug in, can be used for command correction, inputfuckAfter that, you can correct the previous command


The installation is as follows:

brew install thefuck

And then in the.zshrcAdd the following statement to the file

eval $(thefuck --alias)

Search keywords

useweb-searchPlug ins can search using search engines, such as usinggoogleorstackoverflow

$Google oh my Zsh
$stack overflow oh my Zsh


The plug-in does not need to be installed directly in thezshrcIn the filepluginsAdd in

Open remote warehouse

usegit-openPlug in, inputgit openYou can open a warehouse in the browsergithubpage


The installation is as follows:

cd ~/.oh-my-zsh/custom/plugins/
sudo git clone $ZSH_CUSTOM/plugins/git-open

Quick search

fzfPlug in is a general command line fuzzy search tool, depending on Fuzzy keywords, can quickly locate files

adoptcode $(fzf)Command to search for files


The installation is as follows:

brew install fzf


translate shellIs a default Google translation to translate the command line translator

usetransCommand can be translated, plus-spOptions (short for speak) can also be pronounced


The installation is as follows:

brew install translate-shell

Plug in configuration

After the above plug-ins are installed,.zshrcThe configuration of the plug-in section of the file is as follows


# autojump
[[ -s `brew --prefix`/etc/ ]] && . `brew --prefix`/etc/

# thefuck
eval $(thefuck --alias)