侧边栏壁纸
博主头像
IT不良人 博主等级

一天是IT不良人,一辈子都是!

  • 累计撰写 272 篇文章
  • 累计创建 31 个标签
  • 累计收到 8 条评论

目 录CONTENT

文章目录

zsh 安装与配置,使用 oh-my-zsh 美化终端

IT不良人
2026-03-03 / 0 评论 / 0 点赞 / 4 阅读 / 0 字

zsh 安装与配置,使用 oh-my-zsh 美化终端

1 环境配置

1.1 安装基本工具

安装基本工具

# 更新软件源
sudo apt update && sudo apt upgrade -y
# 安装 zsh git curl
sudo apt install zsh git curl -y

设置默认终端为 zsh(注意:不要使用 sudo)。

chsh -s /bin/zsh

1.2 安装 oh-my-zsh

官网:http://ohmyz.sh/。 安装方式任选一个即可。

MethodCommand
curlsh -c "$(curl -fsSL https://install.ohmyz.sh/)"
wgetsh -c "$(wget -O- https://install.ohmyz.sh/)"
fetchsh -c "$(fetch -o - https://install.ohmyz.sh/)"
国内curl镜像sh -c "$(curl -fsSL https://gitee.com/pocmon/ohmyzsh/raw/master/tools/install.sh)"
国内wget镜像sh -c "$(wget -O- https://gitee.com/pocmon/ohmyzsh/raw/master/tools/install.sh)"

注意:同意使用 Oh-my-zsh 的配置模板覆盖已有的 .zshrc

2 、安装 插件

2.1、zsh -autosuggestions

zsh-autosuggestions 是一个命令提示插件,输入命令时自动执行。推测你可能需要输入的命令,按下右键可以快速采用建议。

安装方式:把插件下载到本地的 ~/.oh-my-zsh/custom/plugins 目录。

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

# 中国用户可以使用下面任意一个加速下载
# 加速1
git clone https://github.moeyy.xyz/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# 加速2
git clone https://gh.xmly.dev/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# 加速3
git clone https://gh.api.99988866.xyz/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

2.2、zsh-syntax-highlighting

zsh-syntax-highlighting 是一个命令语法校验插件,在输入命令的过程中,若指令不合法,则指令显示为红色,若指令合法就会显示为绿色。效果如下:

命令语法校验

安装方式:把插件下载到本地的 ~/.oh-my-zsh/custom/plugins 目录。

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

# 中国用户可以使用下面任意一个加速下载
# 加速1
git clone https://github.moeyy.xyz/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# 加速2
git clone https://gh.xmly.dev/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# 加速3
git clone https://gh.api.99988866.xyz/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

2.3、z

oh-my-zsh 内置了 z 插件。z 是一个文件夹快捷跳转插件,对于曾经跳转过的目录,只需要输入最终目标文件夹名称,就可以快速跳转,避免再输入长串路径,提高切换文件夹的效率。效果如下:

使用z跳转目录

2.4、extract

oh-my-zsh 内置了 extract 插件。extract 用于解压任何压缩文件,不必根据压缩文件的后缀名来记忆压缩软件。使用 x 命令即可解压文件,效果如下:

extract 解压

oh-my-zsh 内置了 web-search 插件。web-search 能让我们在命令行中使用搜索引擎进行搜索。使用 搜索引擎关键字+搜索内容 即可自动打开浏览器进行搜索。效果如下:

web-search搜索

重要

最后,记得启用所有插件

3、启用插件

修改 ~/.zshrc中插件列表为:

plugins=(git zsh-autosuggestions zsh-syntax-highlighting z extract web-search)

zsh插件列表

开启新的 Shell 或执行 source ~/.zshrc,就可以开始体验插件。

4、其他注意

允许通配符展开,没有匹配返回空 ,修改~/.zshrc 结尾添加内容:

# 允许通配符展开,没有匹配返回空
setopt nullglob
setopt no_nomatch
0

评论区