利用zsh、oh-my-zsh、powerlevel10k打造一款好看好用的终端

7,517 阅读1分钟

效果图

  • macos 在这里插入图片描述 前面有个可爱的苹果小图标,cd命令 颜色高亮显示, 后面灰色的tessera目录为上次输入过的目录,按➡️直接填充
  • ubuntu 在这里插入图片描述

安装zsh

虚拟终端,兼容bash

  • macos mac默认已经安装了zsh,只需切换
chsh -s /bin/zsh

如果想还原回去执行chsh -s /bin/bash即可

  • ubuntu
sudo apt install zsh
chsh -s /bin/zsh

安装oh-my-zsh

基于zsh命令行,是对zsh的包装,提供了主题配置,插件机制. curl

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

wget

sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

安装Powerlevel9k / Powerlevel10k主题

zsh使用最多的主题

git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k

编辑 ~/.zshrc 设置 ZSH_THEME="powerlevel10k/powerlevel10k".

再增加一行配置:POWERLEVEL9K_MODE="awesome-patched"

安装字体

  • ubuntu
apt-get install fonts-powerline
  • macos
https://github.com/powerline/fonts/blob/master/SourceCodePro/Source%20Code%20Pro%20for%20Powerline.otf
https://github.com/Falkor/dotfiles/blob/master/fonts/SourceCodePro%2BPowerline%2BAwesome%2BRegular.ttf

打开下载的字体,然后按“安装字体”。 在iTerm2中设置字体(Preperence->Profiles->Text→Change Font),选择Source Code Pro + Font Awesome,大小18,最好对“字体”和“非ASCII字体”都进行设置。重新启动iTerm2,以使所有更改生效.

zsh配置主题

source ~/.zshrc

或者执行下面的命令,重新配置

p10k configure

开始配置Powerlevel10k,根据提示(喜好)选择1234或yes、no

iterm2主题配置(针对mac)

下载主题:iterm2colorschemes.com
Preperence->Profiles->Colors->color Presets,点击import,选择刚解压的目录,点击目录下的schemes,选择你想要导入的主题(可多选全部导入),导入后选择自己喜欢的主题,这里我选择了ubuntu主题

一些常用的插件

zsh-autosuggestions

下载插件

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

编辑 ~/.zshrc ,设置plugins

plugins=(zsh-autosuggestions git)

使插件生效

source ~/.zshrc

上次敲过的命令 ,会自动提示,按右方向键➡️确认填充上次的命令

zsh-syntax-highlighting

下载插件

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

写入到配置

echo "source $ZSH_CUSTOM/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc

使插件生效

source ~/.zshrc

命令会自动高亮显示

TIP:

macos: $ZSH_CUSTOM默认值/Users/YOURNAME/.oh-my-zsh/custom