[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$fT9LCOektzJpFmadWnZnGYmPSluu_XpQtUEPaWt9szj8":3},{"code":4,"message":5,"data":6},200,"成功",{"id":7,"createdAt":8,"title":9,"content":10,"summary":11,"image":12,"uid":13,"user":14,"categoryId":21,"category":22,"subCategoryId":24,"subCategory":25,"comments":27,"status":17,"reason":28,"notice":28,"visitCount":29,"commentCount":30,"keywords":31},199,"2026-09-28T09:02:28.091Z","【自定义终端】安装iTerm2和oh-my-zsh到Mac中并自定义字体和插件plugin","# 安装iTerm2和oh-my-zsh到Mac中并自定义字体和插件plugin\n\n## 一、背景\n重换电脑总是需要重新安装一下适合自己的使用环境，结果发现一直没有写一篇如何自定义mac终端配置的博客，特此再来记录一下。\nMac上自带的终端`terminal`外观等配置上，很朴素，即使在设置中配置一些颜色外观，始终还是缺少对一些常见`git、目录`等的详细自定义配置，所以一款自定义好用的终端对在外观、好用上有要求的用户来讲是需要的。\n最通用的莫过于`iTerms`和`oh-my-zsh`。\n\n对比：\n- 系统自带terminal\n![system terminal appearance](https://image.xinwei.ltd/image1790583690190.png)\n\n- iTerm2\n![iterm2 appearance](https://image.xinwei.ltd/image1790583737482.png)\n\n\n## 二、安装\n`iTerm2`的官方网站是：[https://iterm2.com/index.html](https://iterm2.com/index.html)\n`oh-my-zsh`的官方网址是：[https://ohmyz.sh/](https://ohmyz.sh/)\n\n\n### 2.1 下载并安装iterm2\n去往官方网站下载`iTerm2`\n![iterm2 download pic](https://image.xinwei.ltd/image1790583807671.png)\n点击dmg文件安装到电脑中。\n\n### 2.2 下载oh-my-zsh\n可以直接打开`iTerm2`或者系统终端terminal，然后使用命令行下载：\n```terminal\nsh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\"\n```\n\n### 2.3 打开~/.zshrc文件进行配置\n![.zshrc file](https://image.xinwei.ltd/image1790584035711.png)\n\n将`zsh_theme`修改为：\n![modify zsh_theme](https://image.xinwei.ltd/image1790584074307.png)\n\n这样修改后，你的`iTerm2`中的样式是很多字体会不支持（如图），所以我们需要进一步配置字体和插件配置。\n![no-font config appearance](https://image.xinwei.ltd/image1790584231276.png)\n\n## 三、配置字体和插件\n### 3.1 下载字体包并安装到Mac\n通用找的都是`powerline`这个字体最丰富的字体仓库。\n1. 在终端中git克隆到某一个文件夹（比如路径是：~/A）下：\n```terminal\ngit clone https://github.com/powerline/fonts.git --depth=1\n```\n\n2. 终端cd到该字体项目目录下\n```terminal\ncd ~/A/fonts\n```\n\n3. 执行里面的install shell脚本\n```terminal\n./install.sh\n```\n执行完这个命令，仓库中字体就会被安装到Mac电脑中了。\n\n### 3.2 配置iTerm2中的字体集\n打开`iTerm2`中的设置。\n![settings of iterm2](https://image.xinwei.ltd/image1790584642018.png)\n\n选择一个字体（如图是：Meslo LG M DZ for Powerline），你还可以设置成其他的，你点一下，`iTerm2`就直接生效了\n![font config of iterm2](https://image.xinwei.ltd/image1790584962653.png)\n\n\n### 3.3 配置插件\n直接在任意目录执行以下git克隆命令，会把这2个插件代码安装到`oh-my-zsh`的插件`plugin`下\n```terminal\ngit clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions\ngit clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting\n```\n这2个插件一个是`自动补全建议`和`高亮`的插件。\n\n然后要在`.zshrc`中进行指明插件名称：\n- zsh-autosuggestions\n- zsh-syntax-highlighting\n![two plugins](https://image.xinwei.ltd/image1790585501214.png)\n\n### 3.4 更新zsh配置到终端即时生效\n终端执行以下命令：\n```terminal\nsource ~/.zshrc\n```\n\n### 3.5 .zshrc文件配置被覆盖问题\n很多之前已经使用`zsh`的用户，可能在安装`oh-my-zsh`的时候遇到`环境变量覆盖`问题，这个问题`oh-my-zsh`做的很好，不会丢弃你之前的`.zshrc`中的配置，而是生成新文件``来保存之前的配置，如图：\n![.zshrc.pre-oh-my-zsh](https://image.xinwei.ltd/image1790586002357.png)\n\n所以你可以在新生成的`.zshrc`文件中去使用之前的`zsh`配置，直接到`.zshrc`文件中改：\n```.zshrc文件\n...\n# 之前的zsh中的环境变量，如果存在就会同步到zsh环境中\nif [ -f \"$HOME/.zshrc.pre-oh-my-zsh\" ]; then\n     source \"$HOME/.zshrc.pre-oh-my-zsh\" \nfi\n...\n```\n\n以上，应该就是这些了。\n","本地介绍如何在Mac电脑中安装一个优美的自定义终端工具，大家可以参考DIY一下。","https://image.xinwei.ltd/image1790583690190.png",499668042977349,{"phone":15,"userId":13,"nickName":16,"vipType":17,"avatar":18,"sign":19,"createdAt":20},"13121171998","全栈老韩",1,"https://image.xinwei.ltd/images/IMG_5430.JPG","全栈工程师，擅长iOS App开发、前端（vue、react、nuxt、小程序&Taro）开发、Flutter、React Native、后端（midwayjs、golang、express、koa）开发、docker容器、seo优化等。","2024-01-01T16:14:30.305Z",2,{"id":21,"name":23},"IT技术",39,{"id":24,"name":26,"parentId":21},"软件",[],"",3,0,"iterm2,oh-my-zsh,iterm2,iterm2 zsh,zsh,iterm2 mac, iterm2 zsh mac,zsh mac,terminal mac,terminal"]