超清晰步骤 iterm2 ohmyzsh powerline font powerlevel10k 打造好看又实用mac终端

打造好看又实用mac终端

1.png

界面如图

命令行左有各种图标、
右有时间 运行结果等、
下方有cpu ram 内存 网速 git 文件目录等功能,

功能有 自动补全、预检查命令是否正确 语法换颜色显示等


预备

  1. mac
  2. git
  3. homebrew

一、安装配置iterm2

这是个终端。
  1. 官网下载 https://iterm2.com/
  2. 配置下方那堆小功能组件status bar
    打开iterm2 左上角 iterm2 -> preferences -> profiles ->
    session -> 最下面勾选status bar enabled ,紧接着右边configure status bar配置它 自行配置即可
  3. 配置整个界面透明度、模糊度
    左上角 iterm2 -> preferences -> profiles -> window ->window appearance 有两个滑块 第一个是透明度 ,第二个是模糊度 ,自行配置。
  4. 整个iterm2终端界面的背景配色 dark 还是light等等
    左上角 iterm2 -> preferences -> profiles -> window ->colors 右下角有个下拉选项卡 自行配置

二、oh my zsh

一个命令行工具 很多插件配置等,有很大可玩性

1.下载

可以通过 curl 或 wget 两种方式来安装,用一条命令即可安装。
curl 方式安装:
GitHub:

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Gitee ( 国内镜像 )
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"

wget 方式安装
GitHub:

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

Gitee ( 国内镜像 )

sh -c "$(wget -O- https://gitee.com/pocmon/mirrors/raw/master/tools/install.sh)"

2. 使用oh my zsh自定主题(不使用后面powerlevel,易操作但无法自定义想要的)

编辑 ~/.zshrc文件

open ~/.zshrc

找到 ZSH_THEME
robbyrussell 是默认的主题

ZSH_THEME="robbyrussell"

ZSH_THEME="样式名称"
官方给了很多内置样式名称在这https://github.com/ohmyzsh/ohmyzsh/wiki/themes
有中意的样式直接修改robbyrussell为想要的样式就结束终端配置了
想自定义可以继续看本文

!!稍等别走 还得安装字体 第三步 powerline font 不然不显示各种图标和字体样式

三、powerline font

# 先這行,才能用 homebrew 安裝字型。
brew tap homebrew/cask-fonts
# 别的博客们都说这样 其实是不对的 不要用⬇️
# brew tap caskroom/fonts

# 安裝指令
brew install cask font-sauce-code-pro-nerd-font
# 别的博客们都说这样 其实是不对的 不要用⬇️
# brew cask install font-sourcecodepro-nerd-font

然后左上角 iterm2 -> preferences -> profiles -> Text > Change Font,将字体改成SauceCodePro Nerd Font

四、安装配置powerlevel10k

一个方便,实用的命令行主题

1. 安装

git方法

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

Gitee 镜像:

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

2.配置

继续第二步中编辑 ~/.zshrc文件

open ~/.zshrc

设置ZSH_THEME如下

POWERLEVEL10K_MODE='nerdfont-complete'
ZSH_THEME="powerlevel10k/powerlevel10k"

然后

source ~/.zshrc 

重启命令行输入

p10k configure

就会出现一系列问题选项式配置步骤 自行选择,
之后不喜欢了可以再 p10k configure

3.配置苹果 文件 home 等小图标

powerlevel10k的配置文件中去手动更改

vim ~/.p10k.zsh

这是命令行左边区域的配置

32 |  # The list of segments shown on the left. Fill it with the most important segments.
33 |  typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
34 |    # =========================[ Line #1 ]=========================
35 |    # os_icon               # os identifier
36 |    dir                     # current directory
37 |    vcs                     # git status
38 |    # =========================[ Line #2 ]=========================
39 |    newline                 # \n
40 |    # prompt_char           # prompt symbol
41 |  )

这是右边区域的配置

47  |  typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
48  |    # =========================[ Line #1 ]=========================
49  |    status                  # exit code of the last command
50  |    command_execution_time  # duration of the last command
51  |    background_jobs         # presence of background jobs
52  |    direnv                  # direnv status (https://direnv.net/)
53  |    asdf                    # asdf version manager (https://github.com/asdf-vm/asdf)
54  |    virtualenv              # python virtual environment (https://docs.python.org/3/library/venv.html)
55  |    anaconda                # conda environment (https://conda.io/)
.   |   .
.   |   .
.   |   .
101 |    todo                    # todo items (https://github.com/todotxt/todo.txt-cli)
102 |    # swap                  # used swap
103 |    time                    # current time
104 |    # =========================[ Line #2 ]=========================
105 |    newline
106 |    # ip                    # ip address and bandwidth usage for a specified network interface
107 |    # public_ip             # public IP address
108 |    # proxy                 # system-wide http/https/ftp proxy
109 |    # battery               # internal battery
110 |    # wifi                  # wifi speed
111 |    # example               # example user-defined segment (see prompt_example function below)
112 |  )

取消主矢或添加注释可以增添显示的功能方块

所有功能都打开:


2.png
英文名 作用
command_execution_time 上次指令运行经历的时间
time 显示时间
load CPU 负载
ram 显示剩余内存
... ...

通过修改

typeset -g POWERLEVEL9K_***_VISUAL_IDENTIFIER_EXPANSION='👌 '
                                                         ^ 这里

可以改变某功能的图标
图标去这里获取: https://www.nerdfonts.com/cheat-sheet
获取时要点击copy -> icon

完成

还有很多小细节 或者更花哨一点都可以自己去配置 比如整个终端背景 配色等等

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容