了解基础知识
安装必要软件
确保你的电脑已安装 zsh
# apt系
sudo apt install zsh
# yum系
sudo yum install zsh
# pacman系
pacman -S zsh
# dnf系
dnf install zsh
安装完成后执行
chsh -s /bin/zsh
切换默认终端为zsh,重新登录生效,通过命令echo $SHELL
检查是否生效
安装 oh-my-zsh,参考文档:https://github.com/ohmyzsh/ohmyzsh?tab=readme-ov-file#basic-installation
# curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# wget
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# fetch
sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
因为网络原因下载不下来请使用国内gitee镜像
更换默认主题
打开配置文件: vim ~/.zshrc
到这里 https://github.com/ohmyzsh/ohmyzsh/wiki/Themes 选择你喜欢的内置主题,例如: af-magic
,默认主题是 robbyrussell
修改下面的配置:
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="af-magic"
保存并关闭配置文件。
执行 source ~/.zshrc
生效
启用插件
打开配置文件: vim ~/.zshrc
到这里 https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins 选择你喜欢的内置插件,例如:git、web-search、jsontools、z
修改下面的配置,默认安装完git是启用的
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
# plugins=(git) 默认启用这行,启用多个插件用空格隔开
plugins=(git web-search jsontools z)
保存并关闭配置文件。
执行 source ~/.zshrc
生效
ctrl+n/p
在补全选项中上下移动。使用 zsh-autosuggestions 插件
提供更智能的自动补全建议,包括命令、文件名、路径等。
参考链接:https://github.com/zsh-users/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
使用 zsh-syntax-highlighting 插件
提供更丰富的语法高亮功能,支持多种编程语言。
参考链接:https://github.com/zsh-users/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
使用 powerlevel10k 主题
提供强大的主题定制功能,打造炫酷的终端界面。
参考链接:https://github.com/romkatv/powerlevel10k
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
配置参考:
# 主题
ZSH_THEME="powerlevel10k/powerlevel10k"
# 插件
plugins=(git web-search jsontools z zsh-syntax-highlighting zsh-autosuggestions)
zsh 和 oh-my-zsh 赋予了你强大的终端掌控能力,助你在编程、开发、运维等工作中更加高效。发挥你的想象力,打造属于你的个性化高效终端!
注意:
GitHub - ohmyzsh/ohmyzsh GitHub - zsh-users/zsh-syntax-highlighting: Fish shell like syntax highlighting for Zsh. GitHub - zsh-users/zsh-autosuggestions: Fish-like autosuggestions for zsh 终端环境:zsh 、oh-my-zsh、提示主题与 7 效率插件 - POLOXUE's BLOG centos 7安装高版本的zsh教程