zsh

Mac 安装 oh-my-zsh

Mac 安装 oh-my-zsh

Posted by WTJ on January 2, 2016

iTerm2下载与安装

iTerm2官网:https://www.iterm2.com/

iTerm2美化

1、最终效果预览

8514C0F3-1ADA-4B17-AA19-A80444F7A89D

2、将 iTerm2 自带 theme 修改为 Minimal

设置路径:Preferences-Appearance-General-Theme

1D61DAEC-2C57-4210-9A49-DD8DD7D257DA

3、下载、导入并选择配色

主题官网:https://draculatheme.com/iterm/

快速下载

激活主题

  1. iTerm2 > Preferences > Profiles > Colors Tab
  2. Open the Color Presets… drop-down in the bottom right corner
  3. Select Import… from the list
  4. Select the Dracula.itermcolors file
  5. Select the Dracula from Color Presets…

8623D85B-D7D8-4388-BDFE-9AECD84C1E88

4、设置Status Bar

设置路径:Preferences-Profiles-Session-Status bar-Configure Status Bar 可根据自己的需求,选择要展示得插件

1BBE69EC-7101-4AC6-B8E2-2CBE6FEC2E8A

034D1369-EBDA-413A-8E0A-5484F6835D5E

5、安装 iTerm2 Spaceship 主题

主题官网:https://github.com/spaceship-prompt/spaceship-prompt 安装步骤: 1、Clone this repo:

git clone https://[github.com/spaceship-prompt/spaceship-prompt.git](http://github.com/spaceship-prompt/spaceship-prompt.git) "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1

2、Symlink spaceship.zsh-theme to your oh-my-zsh custom themes directory:

ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"

3、配置环境变量

Set ZSH_THEME=”spaceship” in your .zshrc

ZSH_THEME="spaceship"

4、重启环境变量

source ~/.zshrc

6、安装字体 Fira Code Nerd Font

字体官网:https://github.com/ryanoasis/nerd-fonts

0331ECCA-9C09-4E45-A5D9-87FED658B998

89E1A43B-24E9-4178-99CF-36AD848A2708

iTerm2插件配置

1、安装 oh-my-zsh

新Mac 终端默认 shell 为 zsh。

运行 sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)

wangtianji@wangtianjideMBP Desktop % sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Cloning Oh My Zsh...
remote: Enumerating objects: 1289, done.
remote: Counting objects: 100% (1289/1289), done.
remote: Compressing objects: 100% (1242/1242), done.
remote: Total 1289 (delta 28), reused 1185 (delta 27), pack-reused 0
Receiving objects: 100% (1289/1289), 1.07 MiB | 2.16 MiB/s, done.
Resolving deltas: 100% (28/28), done.
From https://github.com/ohmyzsh/ohmyzsh
 * [new branch]      master     -> origin/master
branch 'master' set up to track 'origin/master'.
Switched to a new branch 'master'
/Users/wangtianji/Desktop

Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc.

         __                                     __   
  ____  / /_     ____ ___  __  __   ____  _____/ /_  
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \ 
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / / 
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/  
                        /____/                       ....is now installed!


Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options.

• Follow us on Twitter: https://twitter.com/ohmyzsh
• Join our Discord community: https://discord.gg/ohmyzsh
• Get stickers, t-shirts, coffee mugs and more: https://shop.planetargon.com/collections/oh-my-zsh
打开 oh-my-zsh 配置文件
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

配置项 ZSH_THEME 即为 oh-my-zsh 的主题配置,oh-my-zsh 的 GitHub Wiki 页面提供了 主题列表 当设置为 ZSH_THEME=random 时,每次打开终端都会使用一种随机的主题。

更新配置
source ~/.zshrc

2、oh-my-zsh插件配置

2.1、zsh-syntax-highlighting

作用:平常用的 ls、cd 等命令输入正确会绿色高亮显示,输入错误会显示其他的颜色。

安装

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

配置:修改.zshrc文件

➜  ~ ls ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/
COPYING.md                         README.md                          images                             zsh-syntax-highlighting.zsh
HACKING.md                         changelog.md                       release.md
INSTALL.md                         docs                               tests
Makefile                           highlighters                       zsh-syntax-highlighting.plugin.zsh

打开 oh-my-zsh 配置文件

vim ~/.zshrc

在配置文件结束添加:

plugins=(git zsh-syntax-highlighting)

更新配置

source ~/.zshrc
2.2、zsh-autosuggestions

作用:输入命令时,会给出建议的命令(灰色部分)按键盘 tab 键补全。

git clone https://[github.com/zsh-users/zsh-autosuggestions](http://github.com/zsh-users/zsh-autosuggestions) $ZSH_CUSTOM/plugins/zsh-autosuggestions

2、配置:修改.zshrc文件

plugins=(git zsh-syntax-highlighting zsh-autosuggestions)

更新配置

source ~/.zshrc

自动补全插件

下载 incr 自动补全插件 http://mimosa-pudica.net/src/incr-0.2.zsh 将插件放在 oh-my-zsh 自定义插件目录中

➜  ~ ls ~/.oh-my-zsh/custom/plugins/incr 
incr-0.2.zsh

打开 oh-my-zsh 配置文件

vim ~/.zshrc

在 plugins 中添加 incr 在配置文件结束添加:

source $ZSH/custom/plugins/incr/incr*.zsh

更新配置

source ~/.zshrc

参考:

https://www.jianshu.com/p/64344229778a