终端配置 - iTerm2 + Oh My Zsh

下载并安装 iTerm2

  • 官网地址: https://www.iterm2.com/
  • 安装完成后,在/bin目录下会多出一个zsh的文件
  • 更改默认终端
chsh -s /bin/zsh
or
chsh -s /bin/bash

安装oh-my-zsh

  • GitHub地址: https://github.com/robbyrussell/oh-my-zsh
# 方式1 - curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
or 
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
# 方式2 - wget
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
# linux
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
  • 安装完成后,默认Shell的~/.bash_profile文件默认不再加载,替代的是~/.zshrc。如果在~/.bash_profile里配置了某些设置,需要复制到~/.zshrc

安装PowerLine

pip install powerline-status

安装PowerFonts

# 新建文件夹, 自定义
mkdir ~/repos
cd ~/repos
# git clone
git clone https://github.com/powerline/fonts.git --depth=1
# cd to folder
cd fonts
# run install shell
./install.sh

设置iTerm2字体

iTerm2 -> Preferences -> Profiles -> Text,在Font区域选中Change Font,然后找到Meslo LG字体,有L、M、S可选

设置iTerm2字体

配色方案

  • 安装配色方案
cd ~/repos
git clone https://github.com/altercation/solarized
cd solarized/iterm2-colors-solarized/
open .
  • 在打开的finder窗口中,双击Solarized Dark.itermcolorsSolarized Light.itermcolors即可安装明暗两种配色
  • 配置配色方案
    iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets中选择这两种配色中的一种

agnoster主题

  • 安装agnoster主题
cd ~/repos
git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
cd oh-my-zsh-agnoster-fcamblor/
./install
  • 设置该主题
    打开~/.zshrc文件,然后将ZSH_THEME后面的字段改为agnoster
    ZSH_THEME="agnoster"(agnoster即为要设置的主题)
  • 主题配置
    打开~/.oh-my-zsh/themes/agnoster.zsh-theme,更改prompt_context()函数和prompt_dir()函数
# 第一个为背景色,第二个为字体颜色
...
prompt_context() {
   if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
     # prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
     prompt_segment black yellow "%(!.%{%F{yellow}%}.)%n@%m"
   fi
}
...
prompt_dir() {
   # prompt_segment blue $CURRENT_FG '%~'
   prompt_segment cyan $CURRENT_FG '%~'
}
...

高亮与自动补全插件

cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
git clone https://github.com/zsh-users/zsh-autosuggestions.git
vim ~/.zshrc
## 增加插件 `zsh-syntax-highlighting`要在最后一个
plugins=(
    git
    zsh-autosuggestions
    zsh-syntax-highlighting
)
## 生效高亮 最后一行添加
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

你可能感兴趣的:(终端配置 - iTerm2 + Oh My Zsh)