为了工作更有效率,可以考虑shell终极神器zsh,搭配iterm、oh-my-zsh及autojump、tldr等一系列插件
1、iterm安装
$ brew cask install iterm2
2、iterm颜色主题配置
3、配置Oh My Zsh
Oh My Zsh 是对主题的进一步扩展,地址:https://github.com/robbyrussell/oh-my-zsh
一键安装:
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
安装好之后,需要把 Zsh 设置为当前用户的默认 Shell(这样新建标签的时候才会使用 Zsh):
$ chsh -s /bin/zsh
然后,我们编辑vim ~/.zshrc
文件,将主题配置修改为ZSH_THEME="robbyrussell"
。
zsh 主题列表:https://github.com/robbyrussell/oh-my-zsh/wiki/themes
4、配置Meslo字体
使用上面的主题,需要 Meslo 字体支持,要不然会出现乱码的情况,字体下载地址:Meslo LG M Regular for Powerline.ttf
下载好之后,直接在 Mac OS 中安装即可。
然后打开 iTerm2,按Command + ,
键,打开 Preferences 配置界面,然后Profiles -> Text -> Font -> Chanage Font
,选择 Meslo LG M Regular for Powerline 字体。
当然,如果你觉得默认的12px
字体大小不合适,可以自己进行修改。
另外,VS Code 的终端字体,也需要进行配置,打开 VS Code,按Command + ,
键,打开用户配置,搜索fontFamily
,然后将右边的配置增加"terminal.integrated.fontFamily": "Meslo LG M for Powerline"
,示例:
5. 声明高亮
效果就是上面截图的那样,特殊命令和错误命令,会有高亮显示。
使用 Homebrew 安装:
$ brew install zsh-syntax-highlighting
安装成功之后,编辑vim ~/.zshrc
文件,在最后一行增加下面配置:
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
6. 自动建议填充
这个功能是非常实用的,可以方便我们快速的敲命令。
配置步骤,先克隆zsh-autosuggestions
项目,到指定目录:
$ git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
然后编辑vim ~/.zshrc
文件,找到plugins
配置,增加zsh-autosuggestions
插件。
注:上面声明高亮,如果配置不生效的话,在plugins
配置,再增加zsh-syntax-highlighting
插件试试。
7. 左右键跳转
主要是按住option + → or ←
键,在命令的开始和结尾跳转切换,原本是不生效的,需要手动开启下。
打开 iTerm2,按Command + ,
键,打开 Preferences 配置界面,然后Profiles → Keys → Load Preset... → Natural Text Editing
,就可以了。
8. iTerm2 快速隐藏和显示
这个功能也非常使用,就是通过快捷键,可以快速的隐藏和打开 iTerm2,示例配置(Commond + .
):
9. iTerm2 隐藏用户名和主机名
有时候我们的用户名和主机名太长,比如我的xishuai@xishuaideMacBook-Pro
,终端显示的时候会很不好看(上面图片中可以看到),我们可以手动去除。
编辑vim ~/.zshrc
文件,增加DEFAULT_USER="xishuai"
配置,示例:
可以通过whoami
命令,查看当前用户
➜ /Users/stone >whoami
stone
11. iTerm2 快捷命令
命令 | 说明 |
---|---|
command + t | 新建标签 |
command + w | 关闭标签 |
command + 数字 command + 左右方向键 | 切换标签 |
command + enter | 切换全屏 |
command + f | 查找 |
command + d | 垂直分屏 |
command + shift + d | 水平分屏 |
command + option + 方向键 command + [ 或 command + ] | 切换屏幕 |
command + ; | 查看历史命令 |
command + shift + h | 查看剪贴板历史 |
ctrl + u | 清除当前行 |
ctrl + l | 清屏 |
ctrl + a | 到行首 |
ctrl + e | 到行尾 |
ctrl + f/b | 前进后退 |
ctrl + p | 上一条命令 |
ctrl + r | 搜索命令历史 |
command + ←/→ | 切换tab |
command + ]/[ | 切换分屏 |
12、iterm插件
仅有iterm是不够的,要想更方便的使用,需安装autojump,thefuck,zsh-autosuggestions,tldr(too long,do not read)等插件。
参考:https://www.cnblogs.com/xishuai/p/mac-iterm2.html
http://macshuo.com/?p=676#wechat_redirect
https://www.cnblogs.com/iosdev/archive/2013/07/29/3223232.html