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 hiding
andFloating window
These two options
zsh
Bash is the default shell for Linux and OS X systems.oh my zsh
It’s an enhanced shell
If it’s Mac OS, you should bring it by defaultzsh
Yes, 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.
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
You can view the current environment’sshell
echo $SHELL
You can use the following commandshell
Switch. Especially, switchshell
After that, restart the CLI to take effect
Chsh - S / bin / bash ා switch Bash
Chsh - S / bin / Zsh ා switch Zsh
Next, start the installationoh-my-zsh
Please 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 raw.github.com port 443: Connection refused
Instead, install it at the following address
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
After the installation is completed, you will be prompted whether tozsh
Set 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'.
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ....is now installed!
Please look over the ~/.zshrc file to select plugins, themes, and options.
p.s. Follow us on https://twitter.com/ohmyzsh
p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh
Here is a brief introductionoh-my-zsh
The 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
c/k/k/t/c
After pressing the tab key, the following path will be automatically completed
code/ktsg/ktsg_new/trunk/config
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 config
Command for commandgit branch
Set an alias
$ git config --global alias.b branch
This means that when you want to inputgit branch
Only input is requiredgit b
Just fine
The simpler way is to edit directly~/.gitconfig
File, can achieve the same effect
[alias]
b = branch
But if you just want to inputgb
You want to achieve itgit branch
For the same effect, you need to use the alias function of Linux
actually,zsh
The GIT plug-in has been set by default. The file path is as follows
.oh-my-zsh/plugins/git/git.plugin.zsh
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'
usegst
The 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: html_backup.md
new file: t.html
homebrew
Brew is also calledhomebrew
, is a software package management tool on MAC, which can easily install or uninstall software in MAC
Here ishomebrew
Common 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 ~/.zshrc
To update the configuration
Quick jump
autojump
The plug-in realizes the quick jump between directories. Which directory do you want to go to directlyJ + directory name
No more frequentcd
了
useautojump
Command, or use a short commandj
To 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.zshrc
Add the following statement to the file
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
Command prompt
usezsh-autosuggestions
The 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 https://github.com/zsh-users/zsh-autosuggestions
Syntax highlighting
usezsh-syntax-highlighting
Plug 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 https://github.com/zsh-users/zsh-syntax-highlighting.git
Order correction
usethefuck
Plug in, can be used for command correction, inputfuck
After that, you can correct the previous command
The installation is as follows:
brew install thefuck
And then in the.zshrc
Add the following statement to the file
eval $(thefuck --alias)
Search keywords
useweb-search
Plug ins can search using search engines, such as usinggoogle
orstackoverflow
$Google oh my Zsh
$stack overflow oh my Zsh
The plug-in does not need to be installed directly in thezshrc
In the fileplugins
Add in
Open remote warehouse
usegit-open
Plug in, inputgit open
You can open a warehouse in the browsergithub
page
The installation is as follows:
cd ~/.oh-my-zsh/custom/plugins/
sudo git clone https://github.com/paulirish/git-open.git $ZSH_CUSTOM/plugins/git-open
Quick search
fzf
Plug 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
translate shell
Is a default Google translation to translate the command line translator
usetrans
Command can be translated, plus-sp
Options (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,.zshrc
The configuration of the plug-in section of the file is as follows
plugins=(
git
web-search
autojump
zsh-syntax-highlighting
zsh-autosuggestions
git-open
fzf
)
# autojump
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
# thefuck
eval $(thefuck --alias)