效果
环境
- 系统:ArmBian(Debian)
- Cpu架构:arm64
1 安装ohmyzsh
方式1:查看目前系统是否已经安装Zsh(拿来就用)
ps:Armbian自带Zsh,所以我拿来就用
# 查看系统当前shell程序
echo $SHELL
# 查看系统是否安装了zsh
cat /etc/shells
# 如果已经安装,切换shell为zsh
chsh -s /bin/zsh
# 重启
reboot
方式2:手动安装
项目地址:ohmyzsh
- 前提
apt-get install -y zsh curl wget git
- 安装脚本
# 方式1:Github地址
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 方式2:镜像加速
sh -c "$(wget -O- https://install.ohmyz.sh/)"
恢复Home、End、小键盘
作用:就是按Home,光标可以直接跳到开头等等
- 编辑 zsh的配置文件
vim ~/.zshrc
- 将如下代码插入到配置文件的最后,保存退出
# key bindings
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history
# for rxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
# for freebsd console
bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix
# Fix numeric keypad
# 0 . Enter
bindkey -s "^[Op" "0"
bindkey -s "^[On" "."
bindkey -s "^[OM" "^M"
# 1 2 3
bindkey -s "^[Oq" "1"
bindkey -s "^[Or" "2"
bindkey -s "^[Os" "3"
# 4 5 6
bindkey -s "^[Ot" "4"
bindkey -s "^[Ou" "5"
bindkey -s "^[Ov" "6"
# 7 8 9
bindkey -s "^[Ow" "7"
bindkey -s "^[Ox" "8"
bindkey -s "^[Oy" "9"
# + - * /
bindkey -s "^[Ol" "+"
bindkey -s "^[Om" "-"
bindkey -s "^[Oj" "*"
bindkey -s "^[Oo" "/"
2 安装插件
效果:命令绿色高亮、补全命令灰色提示
2.1 灰色自动补全命令
使用
- 该插件自动补全
你已经输入过得命令
- 在出现灰色提示之后,按小键盘的
→
键,进行补全
安装
- 下载插件的仓库
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
- 修改.zshrc文件
vim ~/.zshrc
-
找到
plugins=(git)
这一行若无plugins=这一行,则新增一行写入
plugins=(git zsh-autosuggestions)
- 修改为
plugins=(git zsh-autosuggestions)
- 修改为
- 生效
source ~/.zshrc
【可选】修复补全文字是白色的bug
参考:zsh-autosuggestion颜色为白色的问题解决
- 编辑zsh配置文件
vim ~/.zshrc
- 追加如下内容
export TERM=xterm-256color
- 生效
source ~/.zshrc
2.2 语法高亮
- 下载插件的仓库
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
- 修改.zshrc文件
vim ~/.zshrc
-
找到
plugins=(git)
若无plugins=这一行,则新增一行写入
plugins=(git zsh-syntax-highlighting)
- 修改为
plugins=(git zsh-syntax-highlighting)
- 修改为
- 生效
source ~/.zshrc
3 更改主题
3.1 ys主题
该主题zsh自带,但是不够炫
- 修改zsh配置文件
vim ~/.zshrc
- 将ZSH_THEME改成ys
ZSH_THEME="ys"
- 更新配置
source ~/.zshrc
3.2 powerlevel10k主题
功能:
- 显示当前时间
- 显示Git
- 显示命令运行的时间
效果
参考:powerlevel10k: 最好看,方便,实用的命令行主题
- 安装P10K
# 方式1:Github地址
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
# 方式2:国内Gitee加速
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
- 在zsh的配置中,启动P10K主题
# sed -i 's/ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' .zshrc
ZSH_THEME="powerlevel10k/powerlevel10k"
- 重启命令行
source ~/.zshrc
- 配置P10K
# 对已经配置的主题效果不满意,可以再次运行该命令,重新配置
p10k configure