经前端同事热心推荐,我用回了 iTerm 2 + Oh My Zsh,为什么说“用回”,之前我尝试过 iTerm + Oh My Zsh,但在工作上遇到几个比较致命的问题解决不了,不得已放弃了 iTerm 这个效率神器。
之前遇到的问题中,最困扰我的是在 SSH 连接服务器之后,窗口标题还是 ssh,多开窗口的情况使我没办法知道我所处的服务器,这个问题在 iTerm 2 中得以解决,我决定使用 iTerm 2 看看。
iTerm 2 能成为程序员口中的神器得益于它比自带终端拥有更强大的可定制化功能,如分屏、多个 Remote 一键自动登录、 命令广播到所有终端等等,配合上 Oh My Zsh 更是锦上添花,Oh My Zsh 是 Zsh Shell 中的插件工具集,官方的 Slogan 是这样的:
Your terminal never felt this good before
你的终端从未这么好用过
让 Zsh 火起来的就是这个 Oh My Zsh,丰富的插件生态、简便的配置方法,好看的主题让 Oh My Zsh 真正成为程序员手上的效率神器,想让自己变得更有效率,可以试试 iTerm2 + Oh My Zsh。
完成效率神器搭建需要安装或者准备这些东西,文章内的安装方法可能会过期,无法安装的化可以根据名字去 Google 一下:
- Mac,目前 iTerm 2 只支持 Mac 系统
- Brew,Mac 安装工具,系统默认
- iTerm 2
- Zsh
- Oh My Zsh
- 主题:spaceship
- 字体: Sauce Code Pro Nerd Font
- 插件列表(插件不在多,够用就好):
- Git,一般都会自带
- AutoJump
- zsh-syntax-highlighting
- zsh-autosuggestions
安装 iTerm 2
官网下载地址
安装 Zsh
brew install zsh
将 Zsh 替换成系统默认 Shell
sudo -s 'echo /usr/local/bin/zsh >> /etc/shells' && chsh -s /usr/local/bin/zsh
安装 Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
安装 Oh My Zsh 主题 spaceship
克隆主题下来:
git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt"
将克隆下来的主题软连接到 zsh 的主题文件夹中
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"
修改~/.zshrc
中的主题名
ZSH_THEME="spaceship"
在命令行输入source ~/.zshrc
让zshrc
生效。
安装 Sauce Code Pro Nerd Font 字体
先執行這行,才能用 homebrew 安裝字型。曾經執行過的人可以跳過這個指令:
brew tap caskroom/fonts
安装字体
brew cask install font-sourcecodepro-nerd-font
安装好之后设置 iTerm 2 -> Preferences -> Profiles -> Text -> Change Font
选择刚才安装的 sourcecodepro-nerd-font
字体
安装各种插件
AutoJump
根据历史的访问记录快速访问目标目录
命令行安装:
brew install autojump
将 autojump 放入~/.zshrc
中的插件设置中:
plugins=(git autojump)
在~/.zshrc
的结尾添加:
[[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
最后在命令行输入source ~/.zshrc
让zshrc
生效。
zsh-syntax-highlighting
命令语法高亮插件,错的命令显示红色,对的命令显示绿色
克隆项目到 Oh My Zsh 的插件文件夹里面:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
将 zsh-syntax-highlighting 放入~/.zshrc
中的插件设置中:
plugins=(git autojump zsh-syntax-highlighting)
在命令行输入source ~/.zshrc
让zshrc
生效。
zsh-autosuggestions
命令补全插件,会显示出你用过的命令
克隆项目到 Oh My Zsh 的插件文件夹里面:
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
将 zsh-autosuggestions 放入~/.zshrc
中的插件设置中:
plugins=(git autojump zsh-syntax-highlighting zsh-autosuggestions)
在命令行输入source ~/.zshrc
让zshrc
生效。
其他好用的插件得靠自己了,好好享受吧。