一、安装homebrew

Homebrew 由开发者 Max Howell 开发,并基于 BSD 开源,是一个非常方便的包管理器工具

1
2
3
4
5
# 官方安装方式
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

# 中科大源安装
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"

下载 zsh终端:

1
brew install zsh

切换成 zsh

1
2
echo $SHELL                  # 查看当前使用的终端
chsh -s /bin/zsh # 切换终端

如果想改回默认,直接使用chsh命令:

1
chsh -s /bin/bash

二、安装iTerm2

1、下载安装

iterm2 是 MAC 下最好的终端工具。

1
2
brew search iterm                  
brew cask install iterm2

2、修改配色

1
2
3
4
5
6
# 找一个目录存放 iterm2 相关的文件
mkdir ~/Desktop/iterm2/themes
# 下载 iTerm2-Color-Schemes
git clone https://github.com/mbadolato/iTerm2-Color-Schemes
# schemes 文件夹就是真实存放配色方案的目录
cd iTerm2-Color-Schemes/schemes

https://iterm2colorschemes.com/ 这里有非常多的配色方案

导入所有配色方案

菜单栏 -> Profiles -> Open Profiles -> Edit Profiles -> 选择 Colors -> 右下角 Color Presets -> Import…

三、安装 oh my zsh

Oh My Zsh 是一款社区驱动的命令行工具,它基于 zsh 命令行,提供了主题配置,插件机制,已经内置的便捷操作。

安装oh my zsh

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

安装成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Time to change your default shell to zsh:
Do you want to change your default shell to zsh? [Y/n] y
Changing your shell to /bin/zsh...
Changing shell for root.
Shell changed.
Shell successfully changed to '/bin/zsh'.

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


Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options.

• Follow us on Twitter: https://twitter.com/ohmyzsh
• Join our Discord community: https://discord.gg/ohmyzsh
• Get stickers, t-shirts, coffee mugs and more: https://shop.planetargon.com/collections/oh-my-zsh

四、配置oh my zsh

打开oh my zsh的配置文件:

1
vim  ~/.zshrc

设置主题

oh-my-zsh 提供了很多内置的配色方案,官方主题列表,可以通过命令来查看:

1
ls ~/.oh-my-zsh/themes

配置项ZSH_THEME 即可配置主题。ZSH_THEME="random" 表示使用随机主题,每次打开终端会随机选择一种主题。

1
ZSH_THEME="random"

使主题生效:

1
zsh           # 作用跟 source .zshrc 一样

非官方主题

添加插件

修改plugins项:

1
2
3
4
5
6
plugins=(
git
autojump
zsh-autosuggestions
zsh-syntax-highlighting
)

插件说明

autojump: 快速跳转的效率工具,它会记录之前访问过的目录,支持模糊匹配。

zsh-autosuggestions:自动提示插件

zsh-syntax-highlighting:语法高亮插件

其他配置

禁用每次下载自动更新

1
export HOMEBREW_NO_AUTO_UPDATE=true

设置命令行中文

1
2
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8