自己在折腾的过程中出现了很多的问题,主要还是依靠一篇经验完成了 iTerm2 的美化,本文借鉴自此经验:
https://zhuanlan.zhihu.com/p/37195261
由于有一些小问题可能会导致美化的失败,想进行一些补充,于是就有了这篇经验。
PS:默认已经安装了 iTerm2 。若是想要将 iTerm2 设置为默认终端,则在文件中任选一个 Unix 可执行文件,右键,显示简介,找到打开方式,在列表中选择 iTerm2 ,点击全部更改即可。
安装必要的包
Homebrew
https://brew.sh/
若是网络好的童鞋们,可以直接复制这行命令,粘贴到 iTerm2 中,输入密码(注:密码不会显示出来,凭感觉输入完后按回车键即可),等待安装完成。
若是网络不好的童鞋们(报错:Failed to connect to raw.githubusercontent.com port 443 after 11 ms: Connection refused)则可以使用国内源进行安装。具体方法参考以下链接:
https://zhuanlan.zhihu.com/p/90508170
这样,一般来说网络问题都能避免了。如果仍然解决不了,可以参考这篇文章:
https://blog.csdn.net/i_CodeBoy/article/details/107386756
Git
https://git-scm.com/download/mac
安装方法如上。使用 Homebrew 的命令安装即可。
MacPorts
https://www.macports.org/install.php
安装方式如上。
Command Line Tools
https://www.freecodecamp.org/news/install-xcode-command-line-tools/
Python pip
https://www.runoob.com/w3cnote/python-pip-install-usage.html
开始美化工作
安装Oh My Zsh
# curl 安装方式
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
或者
# wget 安装方式
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
若使用 wget 方式安装Oh My Zsh,需要先安装 wget ,命令:brew install wget。
安装PowerLine
一行命令即可解决
pip install powerline-status --user
如果仍旧发生报错:zsh: command not found: pip, 则使用命令安装pip:sudo easy_install pip
安装PowerFonts
安装字体库需要首先将项目 git clone 至本地,然后执行源码中的 “install.sh”。
在你习惯的位置新建一个文件夹,如:~/Desktop/OpenSource/
# git clone
git clone https://github.com/powerline/fonts.git --depth=1
# cd to folder
cd fonts
# run install shell
./install.sh
安装好字体之后,点击左上角的iTerm2>>Preferences>>Text>>Font
然后往下拉,选择自己喜欢的字体(注:必须为XXX for Powerline, 否则会乱码)如图:
安装配色方案
使用 git clone 的方式下载源码进行安装:
cd ~/Desktop/OpenSource
git clone https://github.com/altercation/solarized
cd solarized/iterm2-colors-solarized/
open .
在打开的 finder 窗口中,双击 Solarized Dark.itermcolors 和 Solarized Light.itermcolors 即可安装明暗两种配色:
安装完成后,点击左上角的iTerm2>>Preferences>>Colors>>Color Presets
然后选择 Solarized Dark 或 Solarized Light 中任意一个
安装agnoster主题
在 iTerm2 中输入如下命令:
cd ~/Desktop/OpenSource
git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
cd oh-my-zsh-agnoster-fcamblor/
./install
执行完后,输入 vi ~/.zshrc ,打开 zshrc 配置文件,找到 ZSH_THEME,将双引号中内容改为 agnoster 。修改方式:利用方向键移动,按键盘上的i键,进入插入模式,修改完成后按键盘上的esc键,再按:键,输入wq,按回车键保存并退出。如图:
输入 source ~/.zshrc 使得修改生效,或退出重新进入。
安装高亮插件
输入命令
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
vi ~/.zshrc
执行完毕后再次进入 zshrc 配置文件。找到 plugins 。此时 plugins 中应该有了 git ,接着在括号中加入高亮插件,输入 zsh-syntax-highlighting 。请务必保证插件顺序,zsh-syntax-highlighting必须在最后一个。
修改完成后,同样输入 source ~/.zshrc 使得修改生效,或退出重新进入。
如果高亮插件无法生效,则可能是因为 zsh-syntax-highlighting 需要安装到目录,输入:
git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
至此美化工作完成,以下是一些小 tip :
隐藏用户名
在 zshrc 配置文件中加入
DEFAULT_USER=$USER
缩短箭头内的路径
输入:
vim ~/.oh-my-zsh/themes/agnoster.zsh-theme
把下面代码里的%~修改成%1d 即可
prompt_dir() {
prompt_segment green $CURRENT_FG '%~'
}
文章至此结束,若有需要仍会更改。
One comment
好诶