在unix 内核的操做系统中,固然如今衍生出好多分支,linux、OS X都算。 shell 就算和上面这些系统内核指令打交道的一座桥梁,咱们经过键盘输入一种本身容易记忆识别的符号标识(shell 命令),而后shell解析这种命令再反馈给内核去执行一系列操做。linux
那么zsh
和shell
有什么关系呢?git
其实zsh也是一种shell,可是并非咱们系统默认的shell,unix衍生系统的默认shell都是bash。github
cat /etc/shells
查看Mac上已有的shell,一共有6种shell
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
复制代码
chsh -s /bin/zsh
更改使用的shell种类,输入Mac密码来确认更改shell种类,退出终端,从新进入便可。vim
注意:由bash
切换到zsh
后.bash_profile
里面的环境变量的配置便不生效了,须要在~/.zshrc
中从新配置。bash
官网下载:www.iterm2.com/app
安装完成后,在/bin目录下会多出一个zsh的文件。字体
Mac系统默认使用dash做为终端,可使用命令修改默认使用zsh:ui
chsh -s /bin/zsh
复制代码
// 在用户目录下执行git clone命令,clone到本地
git clone https://github.com/altercation/solarized
// 安装目录:/Users/用户/solarized/iterm2-colors-solarized
cd solarized/iterm2-colors-solarized/
open .
// 执行
solarized/osx-terminal.app-colors-solarized/Solarized Dark ansi.terminal
复制代码
在打开的finder窗口中,双击Solarized Dark.itermcolors和Solarized Light.itermcolors便可安装明暗两种配色spa
iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets
中根据我的喜爱选择。
Oh My Zsh 是对主题的进一步扩展
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
复制代码
详细信息能够参考oh-my-zsh的GitHub页面
vi ~/.zshrc
复制代码
zsh 主题列表:github.com/robbyrussel…
# ZSH_THEME="robbyrussell"
# ZSH_THEME="agnoster"
# 我的喜欢avit主题
ZSH_THEME="avit"
复制代码
alias zshconfig='vi ~/.zshrc'
alias vimconfig='vi ~/.vimrc'
alias ll='ls -l'
alias vi='vim'
alias subl='open -a "Sublime Text"'
复制代码
使用上面的主题,须要 Meslo 字体支持,要否则会出现乱码的状况,字体下载地址:Meslo LG M Regular for Powerline.ttf,下载好以后,直接在 Mac OS 中安装便可。而后打开 iTerm2,按cmd + ,
,打开 Preferences 配置界面,而后Profiles -> Text -> Font -> Chanage Font
,选择Meslo LG M Regular for Powerline字体。
另外,VS Code 的终端字体,也须要进行配置,打开 VS Code,按cmd + ,
,打开用户配置,增长一项
"terminal.integrated.fontFamily": "Meslo LG M for Powerline"
复制代码
特殊命令和错误命令,会有高亮显示。使用 Homebrew 安装
brew install zsh-syntax-highlighting
复制代码
安装成功以后,编辑vim ~/.zshrc
文件,在最后一行增长下面配置
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
复制代码
这个功能是很是实用的,能够方便咱们快速的敲命令。 配置步骤,先克隆zsh-autosuggestions项目,到指定目录:
cd ~
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
复制代码
而后编辑vim ~/.zshrc
文件,找到plugins配置,增长zsh-autosuggestions插件
plugins=(git osx zsh-autosuggestions)
复制代码
注:上面声明高亮,若是配置不生效的话,在plugins配置,再增长zsh-syntax-highlighting
插件试试。
有时候由于自动填充的颜色和背景颜色很类似,以致于自动填充没有效果,咱们能够手动更改下自动填充的颜色配置,我修改的颜色值为:586e75
,示例
主要是按住option + → or ←
键,在命令的开始和结尾跳转切换,本来是不生效的,须要手动开启下。
打开 iTerm2,按cmd + ,
键,打开 Preferences 配置界面,而后Profiles → Keys → Load Preset... → Natural Text Editing
,就能够了。
有时候咱们的用户名和主机名太长,终端显示的时候会很很差看(上面图片中能够看到),咱们能够手动去除。编辑vim ~/.zshrc文件,增长DEFAULT_USER="xishuai"配置,示例:
# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"
复制代码
plugins=(git osx autojump)
复制代码