作为软件工程师,我们总是需要经常与终端打交道,在windows系统中,xshell很受欢迎,在macOS系统中,iTerm2比较受欢迎,下面我们就来学习一下iTerm2的使用。
我们先来学习几个比较常用的快捷键
1、在iterm2中,选中某个路径或者某个词汇,iterm2就会自动复制。
2、command + enter 进入与返回全屏模式
3、command + t 新建标签
4、command + f 查找
5、command + d 水平分屏
6、command + shift + d 垂直分屏
7、command + ; 查看历史命令
8、ctrl + u 清除当前行
9、ctrl + a 到行首
10、ctrl + e 到行尾
11、commnad + “+” 字体变大
一些知识
我的mac系统是10.15.7,新的mac系统默认使用zsh
我们可以使用命令查看系统当前的shell,
$ cat /etc/shells
切换shell的命令
chsh -s /bin/zsh
chsh -s /bin/bash
其中,
bash的配置文件是 -/.bash_profile
zsh的配置文件是-/.zshrc
可以看到bash或者zsh的配置文件是隐藏文件
iTrem2下载
iTerm2
下载地址:https://www.iterm2.com/downloads.html
配置iTerm2主题
iTerm2 最常用的主题是 Solarized Dark theme,下载地址:
http://ethanschoonover.com/solarized
下载的是压缩文件,解压,然后打开 iTerm2,按Command +
键,打开 Preferences 配置界面,然后Profiles -> Colors -> Color Presets,在下拉列表中选择 Import,选择刚才解压的solarized->iterm2-colors-solarized->Solarized Dark.itermcolors文件.导入成功后,在 Color Presets下选择 Solarized Dark 主题,就可以了。
设置 iTerm2 背景图片
打开 iTerm2,按Command +
键,打开 Preferences 配置界面Profiles -> Window->Background mage,选择一张自己喜欢的背景图.
配置 Oh My Zsh
Oh My Zsh
是对主题的进一步扩展
安装方式:
## 找到仓库, 然后clone到本地
git clone https://github.com/ohmyzsh/ohmyzsh.git
## 把仓库复制到 .oh-my-zsh目录
cp -r ohmyzsh ~/.oh-my-zsh
## 复制.zshrc
cp ohmyzsh/templates/zshrc.zsh-template ~/.zshrc
## shell换成zsh
chsh -s /bin/zsh
然后,将主题修改为ZSH_THEME="agnoster"
。$ vim ~/.zshrc
输入i
进入编辑模式,将ZSH_THEME=""
编辑为 ZSH_THEME="agnoster"
按下esc
键,退出编辑,:wq
保存退出:
配置 Meslo 字体
使用上面的主题,需要 Meslo 字体支持,要不然会出现乱码的情况,我们需要下载字体Meslo LG M Regular for Powerline.ttf
下载好之后,找到对应的字体,直接在 Mac OS 中安装即可。
然后打开 iTerm2,按Command + ,
键,打开 Preferences 配置界面,然后Profiles -> Text -> Font,
选择 Meslo LG M Regular for Powerline 字体。
声明高亮
特殊命令和错误命令,会有高亮显示。
使用 Homebrew 安装:$ brew install zsh-syntax-highlighting
安装成功之后,编辑vim ~/.zshrc文件,在最后一行增加下面配置:source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
自动建议填充
这个功能是非常实用的,可以方便我们快速的敲命令。
配置步骤,先克隆zsh-autosuggestions项目,到指定目录:
$ git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
然后编辑vim ~/.zshrc
文件,找到plugins配置,增加zsh-autosuggestions
插件。
iTerm2 快速隐藏和显示窗体
打开 iTerm2,打开 Preferences 配置界面,然后Keys →Hotkey,自定义一个快捷键就可以了。
卸载 oh-my-zsh
进入到.oh-my-zsh/tools目录,依次执行$cd .oh-my-zsh/tools
chmod +x uninstall.sh
./uninstall.sh
rm -rif .zshrc