iTerm2_Mac 开发配置手册

Mac下 iTerm2 + oh-my-zsh 安装使用

Mac系统下虽然有【终端terminal】,但更推荐使用【iTerm2 + oh-my-zsh】。

Shell

在操作系统内核外有一层壳,而这层壳就是 shell,它是用户和操作系统交互的桥梁。

shell 包住了系统,用户想要跟系统交互,就必须经过shell。

shell 接收用户或其他程序的命令,把这些命令转化成内核能理解的语言。

我们常见的 shell 有:bash、zsh、csh、ksh、ash 等。

相较于bash,zsh有着许多优点:

  • 更丰富的命令提示
  • 更鲜明的演示标记
  • 更强大的插件支持

Linux 下默认的是 bash ,macOS 在 Catalina 之前的版本默认也是 bash ,后面随着 zsh 越来越流行,macOS 开始将 zsh 作为默认的解释器了。

可以使用命令 chsh 更换登录系统时使用的shell。

# 查看系统中的shells
cat /etc/shells
# 使用zsh
chsh -s /bin/zsh
# 使用bash
chsh -s /bin/bash

oh-my-zsh 简介

默认的 zsh 配置有点烦;oh-my-zsh 可以简化 zsh 配置

oh-my-zsh的 github 地址:GitHub - ohmyzsh/ohmyzsh: A delightful community-driven (with 2,+ contributors) framework for managing your zsh configuration. Includes + optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), + themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.

zsh 对应的配置文件:~/.zshrc

oh-my-zsh 安装

  • 提供了 curl 和 wget 两种安装方式,选择其中之一即可
# curl
sh -c &#;$(curl -fsSL <https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh>)&#;
# wget
sh -c &#;$(wget <https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh> -O -)&#;

修改主题

可以在 Github 上查看都有哪些主题风格:Themes · ohmyzsh/ohmyzsh Wiki · GitHub

配置文件中的 ZSH_THEME 字段配置的就是当前的主题

本地已有的主题都存放在 ~/.oh-my-zsh/themes 目录中

ls ~/.oh-my-zsh/themes

如果要使用第三方主题,下载并保存到 ~/.oh-my-zsh/custom/themes 目录中,并设置主题字段

# 下载第三方主题
git clone <https://github.com/bhilburn/powerlevel9k.git> ~/.oh-my-zsh/custom/themes/powerlevel9k
# 编辑配置文件,配置 ZSH_THEME 字段
vim ~/.zshrc
# source 一下,使之生效
source ~/.zshrc

添加插件

在Github上面查看有哪些可用的插件:Plugins · ohmyzsh/ohmyzsh Wiki · GitHub

我们下载的插件一般存放到 ~/.oh-my-zsh/custom/plugins 目录中。

配置文件中的 plugins 字段配置的就是插件

zsh推荐插件:

1、zsh-autosuggestions 命令补全

2、zsh-syntax-highlighting 语法高亮

3、git

具体步骤如下:

# 切换到插件目录
cd ~/.oh-my-zsh/custom/plugins/
# 下载插件到当前目录
git clone <https://github.com/zsh-users/zsh-autosuggestions>
# 编辑配置文件,配置 plugins 字段
vi ~/.zshrc
# source 一下,使之生效
source ~/.zshrc
原文链接:,转发请注明来源!