我的iTerm2配置完成后是这样子的:
如果对iTerm与zsh和oh-my-zsh的关系不了解的同学,可以看我下面的这篇文章:
iTerm2与zsh和oh-my-zsh的关系
本文用到的文件编辑指令:几个常用的Vim指令
官网地址: http://iterm2.com/downloads.html
$ curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
我安装失败,所以下载资源到本地进行安装。
$ cd ~
$ git clone https://github.com/robbyrussell/oh-my-zsh.git
$ cd ~/Downloads/ohmyzsh-master/tools
$ ./install.sh
解决方案:
如果Safari地址栏中键入: github.com:443
后进入的Github
是自己的仓库,那就退出登录。如果出现的是Github
的登录界面,那就登录Github
。我采用这个方法就解决了上述问题。我猜测是因为我没有给github设置SSH导致的。
终端Clone
项目失败就在Safari
上刷新GitHub
的网页,如果网页能刷新再继续Clone。(WiFi刷新失败可尝试切换热点)
安装成功的截图如下,这里折腾了好久,安装成功给我高兴坏了。
Powerline 是一款 Vim statusline 的插件,它用到了很多特殊的 icon 字符对oh-my-zsh的主题进行展示增强。
$ sudo easy_install pip
出现错误
SyntaxError: invalid syntax
换个方法安装。
$ curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py
$ sudo python3 get-pip.py
pip安装成功
Successfully installed pip-22.0.4
$ pip install powerline-status
安装成功
Successfully installed powerline-status-2.7
Powerline fonts 字体集本质是对一些现有的字体打 patch,把 powerline icon 字符添加到这些现有的字体里,目前对 30 款编程字体打了 patch。oh-my-zsh的一些主题,比如 agnoster,需要用到一些系统没有的特殊字体,所以需要安装 Powerline fonts字体库。
$ git clone https://github.com/powerline/fonts
进入下载好的fonts目录下,执行查看是否有install.sh
文件,如果有就执行下面两步安装Powerline的字体。
$ cd fonts/ 进入fronts目录中
$ ./install.sh
Powerline fonts installed to /Users/teresa/Library/Fonts
进入iTerm 2的设置里找到Profile
中的Text
,设置Font
的字体为Powerline后缀的字体即可。
步骤:iTerm2 -> Preferences -> Profiles -> Text
Nerd font 的原理和 Powerline fonts 是一样的,也是针对已有的字体打 patch,把一些特殊 icon 字符插入进去。Nerd font 是Powerline的超集,下面的桑基图展示了Nerd Fonts中现有的字形组合:
想要了解更多,欢迎移步官网:
Nerd font字体库的官网地址
Nerd font字体库的GitHub仓库地址
git clone https://github.com/ryanoasis/nerd-fonts.git --depth 1
cd nerd-fonts
./install.sh
进入iTerm 2的设置里找到Profile
中的Text
,设置Font
的字体为Powerline
后缀的字体即可。
步骤:iTerm2 -> Preferences -> Profiles -> Text
$ git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor
运行install文件,主题将被自动安装到~/.oh-my-zsh/themes
目录下:
$ cd ~/Downloads/oh-my-zsh-agnoster-fcamblor-master
$ ./install
配置.zshrc
文件
$ vi ~/.zshrc
把ZSH_THEME
设置为agnoster
,重启终端后,agnoster就是当前主题。
ZSH_THEME=”agnoster“
把主题下载在~/.oh-my-zsh/themes/powerlevel10k目录下,这个主题是一个包,直接配置使用。
$ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/themes/powerlevel9k
配置.zshrc
文件。
$ vi ~/.zshrc
把ZSH_THEME
配置为:powerlevel9k/powerlevel9k
。
ZSH_THEME=”powerlevel9k/powerlevel9k“
指导手册上要求先废弃当前正在使用的主题
,再安装powerlevel10k
,配置.zshrc
文件中的ZSH_THEME
=""
废弃当前的主题。
国内直接使用gitee.com的镜像,官方安装指导如下:
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
我与powerlevel9k
的方式保持一致,安装在~/.oh-my-zsh/themes/powerlevel10k
目录下。
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/themes/powerlevel10k
配置.zshrc
文件。
$ vi ~/.zshrc
把ZSH_THEME
配置为:"powerlevel10k/powerlevel10k"
ZSH_THEME=”powerlevel10k/powerlevel10k“
想了解更多使用方法,欢迎移步powerlevel10k官方。
oh-my-zsh自带了一些默认主题,存放在 ~/.oh-my-zsh/themes
目录中,在终端输入 cd ~/.oh-my-zsh/themes && ls
就可以查看到。
cd ~/.oh-my-zsh/themes && ls
目前最全的主题集合是iTerm2-Color-Schemes主题集,它包括Konsole、PuTTY、Xresources、Termite、XFCE 和 Terminator 等终端的主题集合。
iTerm2的配色方案合集也在这个包中。
GitHub仓库是:mbadolato/iTerm2-Color-Schemes,官网是: iterm2colorschemes 。
下图为iTerm2-Color-Schemes的合集包。
schemes
包中主题配色方案可用于iTerm 2中,直接双击.iterminators
文件即可安装该配色方案。
terminal
包中主题配色方案可用于MacOS 的默认终端iterm中。
进入iTerm 2的设置里找到Profile
中的Color
,在color presets
中选择刚才安装的配色方案即可使用。
步骤:iTerm2 -> Preferences -> Profiles -> Color—>color presets
如果输入的命令出错就一直显示红色的,直到输入正确才会变成绿色。
$ cd ~/.oh-my-zsh/custom/plugins
$ git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
.zshrc
文件$ vi ~/.zshrc
在plugins
中配置高亮插件时,zsh-syntax-highlighting
必须放在所有插件的末尾。
plugins=(
git
zsh-syntax-highlighting
)
在.zshrc
文件最后一行增加配置
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
$ cd ~/.oh-my-zsh/custom/plugins/
$ git clone https://github.com/zsh-users/zsh-autosuggestions
.zshrc
文件中配置命令补全插件plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
至此,iTerminal 2 配置完成。
本文参考以下众多网友的文章,感谢网友们的分享。