Home
img of docs

介绍如何在macOS系统上安装和配置Oh My Zsh,一个流行的Zsh配置管理框架,它提供了丰富的功能和主题,以增强终端使用体验。

chou403

/ Mac

/ c:

/ u:

/ 2 min read


一学一个不吱声

安装 oh-my-zsh(二选一),安装之前最好备份一下已有的配置文件,虽然目前 oh-my-zsh 会自动生成一个文件存放之前的配置。

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

###手动安装
git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh

###创建zsh配置文件
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

oh-my-zsh内置自动补全

  • **自动列出目录:**输入 cd 按 tab 键,目录将自动列出,在按 tab 可以切换。
  • **自动补全目录:**例如 /opt/local/bin 这个长路径,只需要 cd /o/l/b 按 tab 键自动补全

zsh-completions:额外补全(二选一)

   ###下载安装
git clone --depth=1 https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions

###添加目录
fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src

###激活
source "$ZSH/oh-my-zsh.sh"

###brew下载安装
brew install zsh-completions

zsh-autosuggestions:历史补全

   ###下载安装
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-autosuggestions

###vi进去 .zshrc配置文件 配置zsh-autosuggestions
plugins=(
    git
    # other plugins...
    zsh-autosuggestions
)

Incremental completion on zsh:实时补全

   ###创建文件夹
mkdir $ZSH_CUSTOM/plugins/incr

###下载
curl -fsSL https://mimosa-pudica.net/src/incr-0.2.zsh -o $ZSH_CUSTOM/plugins/incr/incr.zsh

###配置
echo 'source $ZSH_CUSTOM/plugins/incr/incr.zsh' >> ~/.zshrc

###激活
source ~/.zshrc

zsh-syntax-highlighting:语法高亮

命令错误显示红色,直至正确才为绿色,路径正确会添加下划线

   ###下载安装
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

###vi进去配置zsh-syntax-highlighting
plugins=([plugins...]
         zsh-syntax-highlighting)

安装 Powerlevel10k

Github

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

gitee

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

修改 .zshrc 配置文件

   ZSH_THEME=powerlevel10k/powerlevel10k

安装nerd font

Powerlevel10k 需要依赖 nerd font

   >git clone https://github.com/ryanoasis/nerd-fonts.git --depth 1
>cd nerd-fonts
>./install.sh

终端设置选择字体即可

image-20230918224852566