Skip to main content

如何在_macOS_美化_iterm2_?

在这里插入图片描述

1. 安装 Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Add Homebrew To Path

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[username]/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

2. 安装 zsh

brew install zsh

这应该在您的机器上安装 shell。或者,如果您使用的是 Linux,请遵循本指南;如果您使用的是 Windows,请遵循本指南。

现在,要将 ZSH 设置为默认 shell,请使用以下命令

chsh -s /usr/local/bin/zsh

或者,对于较旧的 Mac OS High Sierra 和之前,您可能需要运行以下命令

chsh -s /bin/zsh

3. 安装 iTerm2

命令行安装

brew install --cask iterm2

或者去官方 iterm2 下载安装。

安装后切换终端打开 iterm2

4. 安装 Git

brew install git

5. 安装 Oh My Zsh

官方Oh My Zsh github Oh My Zsh

 sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

6. 安装 Oh My Zsh PowerLevel10K 主题

git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k

现在它已经安装好了,用你喜欢的编辑器打开“~/.zshrc”文件,然后按如下所示修改“ZSH_THEME”的值:

ZSH_THEME="powerlevel10k/powerlevel10k"

生效

source ~/.zshrc

7. 安装 Meslo Nerd Font

按“y”安装字体,然后退出 iTerm2。

8. 更新 VSCode 终端字体(可选)

打开 settings.json 并添加以下行:

"terminal.integrated.fontFamily": "MesloLGS NF"

9. 配置 PowerLevel10K

重启 iTerm2。您现在应该看到 PowerLevel10K 配置过程。如果不这样做,请运行以下命令:

p10k configure

按照 PowerLevel10K 配置的说明自定义终端

10. 增加终端字体大小

  1. 打开 iTerm2 preferences
  2. 设置Profiles > Text
  3. 增加 font size 至 20px

11. 将 iTerm2 颜色更改为我的自定义主题

打开 iTerm2 通过运行以下命令下载我的颜色配置文件(将添加到下载文件夹):

curl https://raw.githubusercontent.com/josean-dev/dev-environment-files/main/coolnight.itermcolors --output ~/Downloads/coolnight.itermcolors
  1. 打开 iTerm2 首选项
  2. 转到配置文件 > 颜色
  3. 导入下载的颜色配置文件(coolnight)
  4. 选择颜色配置文件 (coolnight)

您可以在这里找到其他主题:Iterm2 配色方案

12. 安装 ZSH 插件

12.1 安装 zsh-autosuggestions

替代 shellfish,它带有一些用于编写终端命令的下一级自动建议。

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

12.2 安装 zsh-syntax-highlighting

语法高亮插件

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

在您想要的编辑器中打开“~/.zshrc”文件,并将插件行修改为您在下面看到的内容。

12.3 加载 wd

wd 插件是我比较喜欢的一个,它的作用就是能够快速的切换到常用的目录。 比如: cd 到一个目录

cd  /usr/nginx/www/html

wd 做一个标识

wd nh

退回至~,执行wd nh就可以跳转至/usr/nginx/www/html

cd ..
wd nh
plugins=(git wd zsh-autosuggestions zsh-syntax-highlighting web-search)

通过运行加载这些新插件:

source ~/.zshrc

参考: