1. 环境配置

1.1 安装基本工具

这里针对的是 linux 用户,mac 本身自带的终端就是 zsh

安装基本工具
# 更新软件源
sudo apt update && sudo apt upgrade -y
# 安装 zsh git curl
sudo apt install zsh git curl -y

设置默认终端为 zsh(注意:不要用 sudo

chsh -s /bin/zsh

1.2 安装oh-my-zsh

官网:https://ohmyz.sh/,安装方式任选一个即可:

Method

Command

curl

sh -c "$(curl -fsSL https://install.ohmyz.sh/)"
# 国内使用
sh -c "$(curl -fsSL https://gitee.com/pocmon/ohmyzsh/raw/master/tools/install.sh)"

wget

sh -c "$(wget -O- https://install.ohmyz.sh/)"
# 国内使用
sh -c "$(wget -O- https://gitee.com/pocmon/ohmyzsh/raw/master/tools/install.sh)"

注意:同意使用 Oh-my-zsh 的配置模板覆盖已有的 ~/.zshrc

安装 oh-my-zsh

2. 配置主题

俗话说好马配好鞍,好的终端自然要美美哒的衣服

2.1 配置主题

sudo wget -O $ZSH_CUSTOM/themes/haoomz.zsh-theme https://cdn.haoyep.com/gh/leegical/Blog_img/zsh/haoomz.zsh-theme

编辑 ~/.zshrc文件,将ZSH_THEMEhaoomz 。当然也可以设置为其他的主题,可以参考:https://github.com/ohmyzsh/ohmyzsh/tree/master/themes

2.2 推荐主题

Powerlevel10k

强烈建议使用 Powerlevel10k 主题!

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

# 中国用户可以使用 gitee.com 上的官方镜像加速下载
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

运行完上述命令后,在~/.zshrcZSH_THEME="powerlevel10k/powerlevel10k" 。接下source ~/.zshrc ,终端会引导你配置 powerlevel10k。

3. 安装插件

oh-my-zsh 现在已经很好了,但有没有办法让它变得更好呢?有的,兄弟有的!那就是插件系统。下面将介绍常用的插件,更多插件可以在awesome-zsh-plugins内查看。

3.1 插件推荐

不是自带的插件需要克隆对应仓库~/..oh-my-zsh/custom/plugins 目录下

  1. zsh-autosuggestions

zsh-autosuggestions是一个命令提示插件,当你输入命令时,会自动推测可能要输的命令,按下右键可以快速采纳。

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

# 中国用户可以使用下面加速下载
git clone https://github.moeyy.xyz/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. zsh-syntax-highlighting

zsh-syntax-highlighting 为一个命令语法校验插件,在输入命令的过程中,若指令不合法,则显示为红色,若指令合法则为绿色。

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 中国用户可以使用下面加速下载
git clone https://github.moeyy.xyz/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. z

内置插件,是一个文件夹快捷跳转插件,对于曾经跳转的目录,只需要输入最终目标文件夹名称即可,避免输入长串路径。

  1. extract

内置插件,可以解压任何文件,使用 x 命令即可解压

  1. web-search

内置插件,可以在命令行中使用搜索引擎进行搜索,自动打开浏览器。

3.2 启用插件

安装完成后需要启用插件

~/.zshrc 中的插件列表为:

plugins=(git zsh-autosuggestions zsh-syntax-highlighting z extract web-search)