[TOC] #### 1. 介绍 --- 前提:本文使用的终端 shell 是 zsh,并且已经安装了 Oh My Zsh Oh My Zsh 有上百个自带的主题,我使用过的也就只有默认主题 robbyrussell 还不错。 也有很多第三方主题插件,使用人数最多,点评最好的是 Powerlevel10k,GitHub 已有 40K 的 Star,可见其受欢迎程度 Powerlevel10k 是一个终端美化主题插件,有着与 Oh My Zsh 搭配天作之合的美称,可以将终端改造的更加美观,炫酷 #### 2. 安装 --- Powerlevel10k 仓库:<https://github.com/romkatv/powerlevel10k> 安装方式查看仓库 README.md 文件,应以 Github 仓库中的安装描述为准,本文使用其中一种 打开终端,运行以下命令,从 Github 上克隆 Powerlevel10k 代码库,并将其放到 Oh My Zsh 的配置文件夹中 ``` git clone --depth=1 git@github.com:romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k ``` 编辑 `~/.zshrc` 文件,修改主题: ``` ZSH_THEME="powerlevel10k/powerlevel10k" ``` #### 3. 配置 --- ##### 第一步:安装字体 重新打开终端窗口将看到以下配置向导 ``` 这是 Powerlevel10k 配置向导。 你看到它是因为你没有定义任何 Powerlevel10k 配置选项。它会问你几个问题提示进行配置。 安装 Meslo Nerd 字体? (y) 是 (推荐). (n) 否. 使用当前字体 (q) 退出,什么也不做 ``` 键入 y 和 n 进入下一步,键入 q 退出配置向导。此时将使用默认配置,当打开新窗口时会再次弹出配置向导 ![](https://img.itqaq.com/art/content/8dcadb2fd38bdb9151738c90b4b71be1.png) 输入 y 安装推荐的字体,可能会出现以下提示,出现该提示时按下回车键结束向导,打开新窗口会重新提示配置向导 ![](https://img.itqaq.com/art/content/efe613aecc11cfad1728e9ab6661abb8.png) 通过该网站获取域名的正确 IP 地址:[www.ipaddress.com](https://sites.ipaddress.com/raw.githubusercontent.com) ,并将其配置到 hosts 文件中 ![](https://img.itqaq.com/art/content/c7e20e87f4a4306843b61b47059a7286.png) ``` 185.199.108.133 raw.githubusercontent.com 185.199.109.133 raw.githubusercontent.com 185.199.110.133 raw.githubusercontent.com 185.199.111.133 raw.githubusercontent.com ``` 重新运行配置向导安装字体又出现了另外一个错误提示 ![](https://img.itqaq.com/art/content/996e44134eaabe203d6de96443713c41.png) 这个错误的原因是因为安装的源在国外,下载很慢,需要切换为国内的源,运行以下命令 ``` /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" ``` 我们只是切换为国内的源,所以要输入序号 6,然后输入电脑的锁屏密码即可自动配置国内源 ![](https://img.itqaq.com/art/content/f864d8cf3b759746ab780b8be8bff8eb.png) 打开新窗口重新运行配置向导,可以发现推荐字体就能安装成功了 ``` Meslo Nerd Font 字体已经安装成功 请重新启动 iTerm2 使其更改生效 1. 点击 iTerm2 退出或使用 ⌘ + Q 退出 2. 打开 iTerm2 按照上面的说明重新启动 iTerm2 非常重要。 仅仅关闭是不够的 iTerm2,单击红色圆圈。您必须单击 iTerm2 → 退出 iTerm2 或按 ⌘ + Q。 ``` ![](https://img.itqaq.com/art/content/4657f7f2a3b3ef6d6a6debf9f254f80d.png) ##### 第二步:校验字体 校验字体是否正常安装:钻石图案能正常展示说明推荐字体安装成功了,输入 y ``` # 这看起来像钻石(旋转的正方形)吗? Does this look like a diamond (rotated square) ? ``` ![](https://img.itqaq.com/art/content/7eb7a0e81048ec379a88f4eb981869fd.png) 同上,下面的操作都是用来校验字体是否正常安装的,都输入 y 即可 ![](https://img.itqaq.com/art/content/7b3f683b2f4610d77a669ee235a35f07.png) ![](https://img.itqaq.com/art/content/a1487a956b7ac981e9d9a5218604dd13.png) ![](https://img.itqaq.com/art/content/bf09e4d1df082c97ba3d528dc32d8d64.png) ##### 第三步:主题风格 Prompt Style 提示样式【选择 3】 ![](https://img.itqaq.com/art/content/00b488f91b9b0f616b238c710852e448.png) Character Set 字符集【选择 1】 ![](https://img.itqaq.com/art/content/b4e34bc167066c5e36c9ae344965ddaa.png) Show current time 时间显示格式【选择 2】 ![](https://img.itqaq.com/art/content/64e4d3a09171b2fede8de6a7e0eb99b6.png) Prompt Separators 分隔符样式【选择 2】 ![](https://img.itqaq.com/art/content/742f51a6fd6f03deac767b4b80d97f70.png) Prompt Heads 头部样式【选择 1】 ![](https://img.itqaq.com/art/content/12bb5675bcece3e1dcc862712a573107.png) Prompt Tails 尾部样式【选择 2】 ![](https://img.itqaq.com/art/content/634877533c4975d7b428153f140ffa8f.png) Prompt Height 提示高度。命令输入在第 1 行还是第 2 行【选择 2】 ![](https://img.itqaq.com/art/content/acfa86070e4b8fc9d9f9090ccc531c72.png) Prompt Connection 首尾连接方式 1 不连接 2 虚线 3 实线【选择 2】 ![](https://img.itqaq.com/art/content/765c400fa1d4c3bdee89212126532e98.png) Prompt Frame 是否加 frame,选 1 首尾都不加 frame【选择 1】 ![](https://img.itqaq.com/art/content/952ed63ae5b1dab486c568727d6622bb.png) Connection Color 首尾连接线颜色【选择 1】 ![](https://img.itqaq.com/art/content/7a303d6f8cdfdf7b6788e55020c8ce64.png) Prompt Spacing 行间距。1 紧凑 2 稀疏【选择 1】 ![](https://img.itqaq.com/art/content/14f089b57c07737c3b98b4741b18a34d.png) Icons 图标 1 很少的图标 2 尽可能的展示图标【选择 2】 ![](https://img.itqaq.com/art/content/c3436092215b6e7ee7651b645177b239.png) Prompt Flow 命令耗时的显示,1 concise 简洁 2 Fluent 流利【选择 1】 ![](https://img.itqaq.com/art/content/6b0be6ff7f8f9c6cbf95efa8a1c35c98.png) Enable Transient Prompt 是否只显示瞬时的提示行,选 n 的话每次命令的提示都会保留【选择 n】 ![](https://img.itqaq.com/art/content/8ae1822074956fdcdee886f77e1c1277.png) Instant Prompt Mode 提示行模式,选 verbose【选择 1】 ![](https://img.itqaq.com/art/content/84e41253b3b4cebc5b6d3725087ffe5f.png) 是否更改 `~/.zshrc`【选择 y】将在该文件末尾添加以下内容 ``` # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh ``` ![](https://img.itqaq.com/art/content/94eafab88702e1fd57c0ffdea086f2dc.png) 最后的效果如下所示 ![](https://img.itqaq.com/art/thumb/a97320185d9419eab964ac89b64b2482.png) #### 4. 命令 --- 再次配置 ```shell p10k configure ```