Mac配置终端环境(iTerm2+Zsh+oh-my-zsh)
参考文章:
https://www.cnblogs.com/presleyren/p/10863416.html
https://blog.csdn.net/maczhushou/article/details/108534532
https://blog.csdn.net/qq_43531694/article/details/106862753
https://segmentfault.com/a/1190000014992947
本文iTerm2使用OS 10.14+
1、Iterm2下载&安装
1.1、下载
1.2、安装
iTerm2-3_4_10.zip解压缩即可使用,可以移到应用程序中在启动台中启动
1.3、配置iTerm2
1.3.1、设置Meslo LG M Regular for Powerline字体(agnoster主题需要该字体)
1.3.2、设置配色方案
截图中设置的是Solarized Dark配色
1.3.3、iTerm2 快速隐藏和显示快捷键
1.3.4、iTerm2透明度设置
command + u 快捷键可取消背景设置
1.3.5、ITerm2快捷命令
命令 | 说明 |
---|---|
command + , | 打开设置 |
command + o | 打开Profiles |
command + u | 打开/取消窗口设置 |
command + t | 新建标签 |
command + w | 关闭标签 |
command + enter | 切换全屏 |
command + f | 查找 |
command + d | 垂直分屏 |
command + shift + d | 水平分屏 |
command + shift + h | 查看剪贴板历史 |
ctrl + u | 清除当前行 |
ctrl + l | 清屏 |
ctrl + a | 到行首 |
ctrl + e | 到行尾 |
ctrl + f/b | 前进后退 |
ctrl + p | 上一条命令 |
ctrl + r | 搜索命令历史 |
2、zsh
# Mac系统默认使用bash作为终端,可以使用命令修改默认使用zsh:
chsh -s /bin/zsh
#如果想修改回默认bash,同样使用chsh命令即可:
chsh -s /bin/bash
3、oh-my-zsh
3.1、卸载老的oh-my-zsh
进入到.oh-my-zsh/tools
目录进行卸载
# 切换到目录下执行卸载脚本
cd .oh-my-zsh/tools
sudo sh uninstall.sh
# 切换到用户目录下再执行删除命令,删除历史文件以及当前配置文件
rm -rf .zsh*
3.2、下载&安装oh-my-zsh
# 安装brew方式(这里用的是国内的镜像源)
sh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
# 最好先更新一下zsh版本,因为安装oh-my-zsh需要zsh版本在v4.3.9及以上
brew install 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 -)"
# 下载报 443:Connection refused,可参考该文章解决:https://blog.csdn.net/qq_43531694/article/details/106862753
3.3、配置
3.3.1、.bash_profile用户启动文件生效
# 编辑~/.zshrc文件,
vim ~/.zshrc
# 编辑~/.zshrc文件,添加以下命令
# 用户环境变量生效(用户启动文件生效)
source ~/.bash_profile
3.3.2、主题设置为agnoster
# 编辑~/.zshrc文件,
vim ~/.zshrc
# 编辑~/.zshrc文件设置主题
ZSH_THEME="agnoster"
3.3.3、高亮插件
# Homebrew安装高亮插件
brew install zsh-syntax-highlighting
# 编辑~/.zshrc文件,
vim ~/.zshrc
# 设置高亮插件,在.zshrc文件中插入
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
3.3.4、自动建议填充插件
# clone zsh-autosuggextions到oh-my-zsh的插件目录下
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
# 编辑~/.zshrc文件,
vim ~/.zshrc
# 设置自动建议填充插件,在.zshrc文件中插入
plugins=(git zsh-autosuggestions)
# 高亮样式(白色背景上显示带有粗体、下划线、亮蓝色文本)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#87cefa,bg=white,bold,underline"
# 首先尝试从您的历史记录中查找建议,但是,如果找不到匹配项,则会从完成引擎中查找建议。
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
3.3.5、iTerm2通过oh-my-zsh隐藏用户名和主机名
# 编辑~/.zshrc文件,
vim ~/.zshrc
# 增加默认用户配置(通过whoami 命令获取用户)
DEFAULT_USER="${user}"