iTerm2+oh-my-zsh+ plugin set, create the best mac terminal

1. Replace the shell parser

The shell is a command parser. The common zsh and bash on mac are both shells. Zsh is basically compatible with bash. With the addition of the oh-my-zsh tool, it is recommended to use zsh.

1.1 View and switch

echo $SHELL        # 查看当前使用shell
chsh -s /bin/bash  # 切换为bash
chsh -s /bin/zsh   # 切换为zsh

1.2 Configuration file location

  • Configuration file read by bash: ~/.bash_profile file

  • Configuration file read by zsh: ~/.zshrc file

When switching from bash to zsh, if you don’t want to reconfigure the .zshrc file again, you can add source ~/.bash_profile to the .zshrc file to read the configuration directly from the .bash_profile file.

1.3 Script takes effect

After modifying the configuration file, execute source ~/.bash_profile (take .bash_profile as an example), so that the system can read the latest configuration.

1.4 Explanation of environment variable file

  1. /etc/profile: (Single-user system environment variables) This file sets the environment information for each user of the system. When the user logs in for the first time, the file is executed. And from the configuration file in the /etc/profile.d directory Collect shell settings. )

  1. /etc/bashrc: (single-user variable) Execute this file for each user who runs the bash shell. When the bash shell is opened, this file is read (that is, bashrc is executed every time a new terminal is opened).

  1. ~/.bash_profile: (environment variable for each user) Each user can use this file to enter the shell information dedicated to their own use. When the user logs in, the file is only executed once. By default, some environment variables are set and the user's .bashrc file is executed.

  1. ~/.bashrc: This file contains bash information specific to your bash shell. This file is read when you log in and every time you open a new shell.

  1. ~/.bash_logout: Execute this file every time you exit the system (exit the bash shell). In addition, the variables (global) set in /etc/profile can act on any user, while the settings in ~/.bashrc, etc. Certain variables (local) can only inherit the variables in /etc/profile, they are "parent-child" relationship.

  1. ~/.bash_profile: It is for interactive and login mode to enter bash operation ~/.bashrc is for interactive non-login mode to enter bash operation. Usually the settings of the two are roughly the same, so usually the former will call the latter.

2. Install oh-my-zsh

oh-my-zsh is a more powerful command line tool that frees your hands. It is more cool and efficient than the bash that comes with the system. It can realize a series of cool functions such as more powerful command completion and command highlighting. At the same time, various customization options are supported, and extensions are supported.

2.1 Installation

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

2.2 Install the self-library for the system, for iterm to choose

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

After installation, choose a Powerline font: iterm2 -> Preferences -> Profiles -> Text -> Font -> Change Font (I use Meslo LG)

2.3 Modify iterm theme

Official theme collection

~/.zshrc change theme ZSH_THEME="agnoster"

2.4 Install the color matching library

git clone [email protected]:mbadolato/iTerm2-Color-Schemes.git

Change the color scheme: iterm2 -> settings -> Profiles -> Text -> Colors -> Change Colors -> import -> iTerm2-Color-Schemes/schemes/select all import, choose a color scheme you like.

2.5 Installing plugins

2.5.1 Command line highlighting

 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
 echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
 # ${(q-)PWD} 的含义是将当前工作目录的路径作为一个变量,并对该变量进行引号转义,以便在后续的 shell 命令中使用。
 # 最终输入结果:source /Users/liang/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

2.5.2 Command auto-completion

1. homebrew installation

  • Execute brew install zsh-autosuggestions

  • After successful installation:

#编辑配置文件
vim ~/.zshrc

#在最后一行增加下面的代码
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

#退出编辑后执行使配置生效
source ~/.zshrc

2. git command installation

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

#编辑配置文件
vim ~/.zshrc

#找到plugins配置,在括号内增加zsh-autosuggestions,与其他插件之间使用空格分隔开
plugins=(zsh-autosuggestions)

#退出编辑后执行使配置生效
source ~/.zshrc

Press tab to complete the command, the effect picture:

3. autojump automatic jump tool

autojump提供了一种快速进行文件目录导航的方式。 它会把你在命令行中最常用的目录保存到一个数据库里,然后根据你访问的频次添加不同的权重。

访问越频繁,权重越高,排名就越先前,跳转的命令就越简洁。

注意:目录在通过autojump跳转之前必须先访问,然后在autojump的数据库中才有记录

j是autojump命令的简写,任何可以用autojump的地方都可以以j命令替换

3.1 安装

3.1.1 方式一:homebrew安装

  • brew install autojump

  • 安装完成后,进行如下操作:

#编辑配置文件
vim ~/.zshrc

#在最后一行增加下面的代码
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh

#退出编辑后执行使配置生效
source ~/.zshrc 

3.1.2 方式2:git命令安装

#github镜像
git clone git://github.com/joelthelion/autojump.git

#进入目录,执行安装命令
./install.py

在安装过程中,会在~/下建立.autojump文件夹,如果github镜像无法下载,请使用gitee镜像下载

#gitee镜像
git clone https://gitee.com/null_454_5218/autojump.git $ZSH_CUSTOM/plugins/autojump

#进入目录autojump中
cd $ZSH_CUSTOM/plugins/autojump

#执行安装命令
./install.py

安装成功后,进行如下操作:

#编辑配置文件
vim ~/.zshrc

#找到plugins配置,在括号内增加autojump,与其他插件之间使用空格分隔开
plugins=(autojump)

#在文件最后一行或者plugins=()后另起一行添加如下内容
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh

#退出编辑后执行使配置生效
source ~/.zshrc 

3.2 验证安装成功

autojump --version

3.3 使用

  1. j

跳转到指定目录下

j ~/Desktop/dxlWorkspace  # 跳转到~/Desktop/dxlWorkspace目录下,下次直接输入 j dxl就可以直接跳转
  1. jo

跳转到该目录,并使用终端打开,相当于cd ~/Desktop/dxlWorkspace && open ./

jo ~/Desktop/dxlWorkspace 
  1. 查看记忆权重

j --stat

这个工具优点在于能记忆每次输入跳转,每条记忆记录都有权重,方便下次用更简洁的命令,达到目录跳转的目的。

4. 参考

  1. iTerm2安装配置使用指南——保姆级

  1. linux之autojump命令

5. 结语

我是滚石,一名热爱前端的菜鸟程序员,成长路上,欢迎一起交流讨论,一起进步!

Guess you like

Origin blog.csdn.net/SmileLife123/article/details/129112725
Recommended