caitiao的博客

就现在,Just do it

0%

iterm2配置123

拿到mac电脑后,第一件事一般都会需要配置一个适合自己用的终端。我一般选择iterm2作为日常工作的终端,下面我就来记录下怎么配置我的iterm2。

  1. 安装iterm2
    1
    brew install iterm2
  2. oh-my-zsh
    我电脑默认的sh是zsh,有了oh-my-zsh配置zsh就事半功倍。
  • 检查当前系统支持的shell
    1
    cat /etc/shells
  • 将当前默认shell设置为zsh
    1
    chsh -s /bin/zsh
  • 安装oh-my-zsh
    1
    sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  1. 配置zsh主题

    1
    2
    3
    vim ~/.zshrc
    找到ZSH_THEME配置你想配置的主题,你可以在https://github.com/ohmyzsh/ohmyzsh/wiki/Themes 找到自己想要的主题
    我的配置:ZSH_THEME="agnoster"
  2. 字体配置
    下载特定字体,以避免无法解码

    1
    2
    3
    4
    5
    6
    # clone
    git clone https://github.com/powerline/fonts.git --depth=1
    # install
    ./fonts/install.sh
    # 清楚当前字体目录
    rm -rf fonts

    打开iterm2首选项,配置文件->文件->字体,选择“Meslo LG M for Powerline”字体,如果这一步不设置,可能会出现乱码

  3. 安装推荐的插件

  • 语法高亮插件(syntax-highlighting)
    1
    2
    3
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
    vim ~/.zshrc
    plugins=(zsh-syntax-highlighting)
  • 自动补全插件(autocomplete)
    1
    2
    3
    git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
    vim ~/.zshrc
    plugins=(zsh-syntax-highlighting zsh-autosuggestions)
  1. iTerm2隐藏用户名和主机名
    通常在Shell中默认的用户名和主机名加在一起会很长,使用的时候影响观感,我们可以通过配置去除掉
    1
    2
    3
    4
    5
    vim ~/.zshrc
    # 新增DEFAULT_USER="xxxxx"配置
    DEFAULT_USER="xxxxx" #xxxxx是当前用户名,可以通过whoami获得
    # 退出并保存后,使配置生效
    source ~/.zshrc