macOS 终端配置

2,740 阅读1分钟

1 安装 iTem2

  1. 首先下载并安装 iTem2 这个软件, 比 MAC 自带的终端更加强大。
  1. iTem2 设置为系统默认终端:

image-20181209103742136

2 设置配色方案

使用 solarized 效果还不错。点开官网,下载,解压,然后打开 iTerm2 下的偏好设置 preference ,点开 profiles 下的colors 选项,点击右下角的 Color Presets 选项,选择import ,导入解压到的 solarized 文件下的Solarized Dark.itermcolors。

3 安装 oh-my-zsh

使用 crul 安装:

sh -c "$(curl -fsSL https://raw.github.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 -)"

4 安装主题

用 vim 打开隐藏文件 .zshrc ,修改主题为 agnoster:

ZSH_THEME="agnoster"

应用这个主题需要特殊的字体支持,否则会出现乱码情况,这时我们来配置字体:

  1. 使用 Meslo 字体,点开连接点击 view raw 下载字体。
  2. 安装字体到系统字体册。
  3. 应用字体到 iTerm2 下 iTerm2 -> Preferences -> Profiles -> Text -> Change Font
  4. 重新打开iTerm2窗口,这时便可以看到效果了。

image-20181209111427105

5 自动提示命令

当我们输入命令时,终端会自动提示你接下来可能要输入的命令,这时按 → 便可输出这些命令,非常方便。

  1. 克隆仓库到本地 ~/.oh-my-zsh/custom/plugins 路径下:
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  1. 用 vim 打开.zshrc 文件修改 plugins 选项:
plugins=(zsh-autosuggestions git)
  1. 重新打开终端窗口:

image-20181209111016418

PS:当你重新打开终端的时候可能看不到变化,可能你的字体颜色太淡了,我们把其改亮一些。

  1. 移动到 ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions 路径下
cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
  1. vim 编辑 zsh-autosuggestions.zsh 文件:
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10'

6 语法高亮

  1. 使用homebrew安装 zsh-syntax-highlighting 插件。
brew install zsh-syntax-highlighting
  1. 配置 .zshrc 文件,插入一行:
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  1. 应用配置:
source ~/.zshrc

PS:安装 Homebrew 包管理工具:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"