0%

iterm2配置zsh和常用插件

直接看效果图

1

1

1. 安装

1.1 安装 ohmyzsh

https://github.com/ohmyzsh/ohmyzsh

注意安装会覆盖 .zshrc, 提前备份下

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

.zshrc文件加下面配置

1
2
# ~/.zshrc
export ZSH="/Users/liuwei/.oh-my-zsh"

重置下配置文件

1
source $ZSH/oh-my-zsh.sh

1.2 安装主题 powerlevel10k

https://github.com/romkatv/powerlevel10k

1
2
3
4
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

# 设置主题 ~/.zshrc
ZSH_THEME="powerlevel10k/powerlevel10k"
  • 主题配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# ~/.zshrc
POWERLEVEL9K_MODE='nerdfont-complete'
ZSH_THEME="powerlevel10k/powerlevel10k"
POWERLEVEL9K_CONTEXT_TEMPLATE='%n'
POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND='white'
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%F{014}\u2570%F{cyan}\uF460%F{073}\uF460%F{109}\uF460%f "
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
POWERLEVEL9K_NODE_VERSION_BACKGROUND="002"
POWERLEVEL9K_NODE_VERSION_FOREGROUND="black"
POWERLEVEL9K_GO_VERSION_BACKGROUND="001"
POWERLEVEL9K_GO_VERSION_FOREGROUND="black"
POWERLEVEL9K_WIFI_BACKGROUND="003"
POWERLEVEL9K_WIFI_FOREGROUND="black"
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon context ssh dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status proxy anaconda node_version go_version wifi)

# 在终端下执行下面的命令, 可以看到代号对应的颜色
# for i in {0..255}; do print -Pn "%K{$i} %k%F{$i}${(l:3::0:)i}%f " ${${(M)$((i%6)):#3}:+$'\n'}; done

1.3 安装字体

下载推荐字体

也可选择其他字体安装

1
2
3
4
# 几个字体仓库
https://github.com/powerline/fonts
https://github.com/gabrielelana/awesome-terminal-fonts
https://github.com/ryanoasis/nerd-fonts/

然后在iterm2里面,把字体改成后缀为powerline的字体就行了
1

2. 插件

2.1 git

1
2
#.zshrc
plugins=(git)

2.2 自动补充

https://github.com/zsh-users/zsh-autosuggestions

1
2
3
4
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

#.zshrc
plugins=(zsh-autosuggestions)

2.3 语法高亮

https://github.com/zsh-users/zsh-syntax-highlighting

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

#.zshrc
plugins=(zsh-syntax-highlighting)

3. 配色

3.1 配色项目

1
2
3
https://github.com/dracula/dracula-theme/ # 选用的这个!!!好看!!!支持各种终端,吸血鬼配色
https://github.com/mbadolato/iTerm2-Color-Schemes # 这上面好多, 慢慢挑
https://github.com/MartinSeeler/iterm2-material-design

3.2 安装dracula

https://github.com/dracula/iterm

1
2
3
4
5
6
7
8
9
git clone https://github.com/dracula/iterm.git

#Activating theme
iTerm2 > Preferences > Profiles > Colors Tab
Open the Color Presets... drop-down in the bottom right corner
Select Import... from the list

Select the Dracula.itermcolors file
Select the Dracula from Color Presets...

4. 遇到的问题

4.1 图案不显示

1
2
POWERLEVEL9K_MODE='nerdfont-complete' #这句话一定要在下面source之前
source $ZSH/oh-my-zsh.sh

5. 参考资料

给作者打赏,可以加首页微信,咨询作者相关问题!