导语
用 iTerm2 与 Oh My Zsh的结合替代 macOS 上较为“丑陋”的 terminal属于拿到新 mbp 的基操。本文不是新版本,只是属于验证过的可实践的成熟操作过程。

github
操作过程
# Mac系统默认使用dash作为终端,可以使用命令修改默认使用zsh
chsh -s /bin/zsh
# 如果想修改回默认dash,同样使用chsh命令即可:
chsh -s /bin/bash
# 安装Oh my zsh
## 安装方法有两种,可以使用curl或wget,看自己环境或喜好:
### curl 安装方式
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
### wget 安装方式
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
# 安装PowerLine (如果不是python3,pip3可以替换为pip)
pip3 install powerline-status --user
# 安装PowerFonts
mkdir ~/Desktop/OpenSource/
cd ~/Desktop/OpenSource/
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh
安装好字体库之后,我们来设置iTerm2的字体,具体的操作是iTerm2 -> Preferences -> Profiles -> Text,在Font区域选中Change Font,然后找到Meslo LG字体。有L、M、S可选,看个人喜好:

set font
# 安装配色方案
cd ~/Desktop/OpenSource
git clone https://github.com/altercation/solarized
cd solarized/iterm2-colors-solarized/
open .
再次进入iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets中根据个人喜好选择这两种配色中的一种即可:

set color
# 安装主题
## 下载agnoster主题,执行脚本安装
cd ~/Desktop/OpenSource
git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
cd oh-my-zsh-agnoster-fcamblor/
./install
## 拷贝完成后,执行命令打开zshrc配置文件,将ZSH_THEME后面的字段改为agnoster。
vi ~/.zshrc
# 安装高亮插件
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
vi ~/.zshrc
这时我们再次打开zshrc文件进行编辑。找到plugins,此时plugins中应该已经有了git,我们需要把高亮插件也加上:

请务必保证插件顺序,zsh-syntax-highlighting必须在最后一个。
然后在文件的最后一行添加:source
~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
执行命令使刚才的修改生效:
source ~/.zshrc
# 可选择、命令补全
## 跟代码高亮的安装方式一样,这也是一个zsh的插件,叫做zsh-autosuggestion,用于命令提议和补全。
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions
vi ~/.zshrc
找到plugins,加上这个插件即可:

最终效果

© 版权声明
文章版权归作者所有,未经允许请勿转载。



mac下终端只有warp和其他