漂亮的命令行-1:Zsh

效果

环境

  • 系统: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

  1. 前提
apt-get install -y zsh curl wget git
  1. 安装脚本
# 方式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 后HOME/END 键以及小键盘失效

  1. 编辑 zsh的配置文件
vim ~/.zshrc
  1. 将如下代码插入到配置文件的最后,保存退出
# 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 安装插件

效果:命令绿色高亮、补全命令灰色提示
image

2.1 灰色自动补全命令

使用

  1. 该插件自动补全你已经输入过得命令
  2. 在出现灰色提示之后,按小键盘的键,进行补全

安装

  1. 下载插件的仓库
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  1. 修改.zshrc文件
vim ~/.zshrc
  • 找到plugins=(git)这一行

    若无plugins=这一行,则新增一行写入plugins=(git zsh-autosuggestions)

  1. 生效
source ~/.zshrc

【可选】修复补全文字是白色的bug

参考:zsh-autosuggestion颜色为白色的问题解决

  1. 编辑zsh配置文件
vim ~/.zshrc
  1. 追加如下内容
export TERM=xterm-256color
  1. 生效
source ~/.zshrc

2.2 语法高亮

  1. 下载插件的仓库
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
  1. 修改.zshrc文件
vim ~/.zshrc
  • 找到plugins=(git)

    若无plugins=这一行,则新增一行写入plugins=(git zsh-syntax-highlighting)

  1. 生效
source ~/.zshrc

3 更改主题

3.1 ys主题

该主题zsh自带,但是不够炫

  1. 修改zsh配置文件
vim ~/.zshrc
  1. 将ZSH_THEME改成ys
ZSH_THEME="ys"
  1. 更新配置
source ~/.zshrc

3.2 powerlevel10k主题

功能:

  1. 显示当前时间
  2. 显示Git
  3. 显示命令运行的时间

效果

参考:powerlevel10k: 最好看,方便,实用的命令行主题

  1. 安装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
  1. 在zsh的配置中,启动P10K主题
# sed -i 's/ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' .zshrc
ZSH_THEME="powerlevel10k/powerlevel10k"
  1. 重启命令行
source ~/.zshrc
  1. 配置P10K
# 对已经配置的主题效果不满意,可以再次运行该命令,重新配置
p10k configure

21 个赞

現學現賣。插眼
:grin::grin::grin::grin::grin:

3 个赞

支持分享

1 个赞

感谢分享

2 个赞

感谢

1 个赞

好东西 感谢分享

插眼

1 个赞

看了这个帖子才知道主题已经更新到P10K了,我还在用4年前配置过的P9K,火速更新一下:partying_face:

awesome

1 个赞

这个还是不错的。

mark:命令行工具

1 个赞

你好,朋友。我能在 Windows 上创建这个命令行吗?如果你有其他建议,请告诉我。

@radio

1 个赞

Windows用oh-my-posh

2 个赞

这是linux使用的命令工具
如果在windows上,建议试试这位大佬推荐的工具

2 个赞

感谢分享

1 个赞

oh-my_zsh 好像有点慢

2 个赞

Mark,命令行,zsh

1 个赞

愿你美化归来,仍是bash :yum:

1 个赞

只有这几个插件的话不需要oh my zsh,直接手动装就行了。oh my zsh性能不好。另外再推荐两个自动提示插件,一个叫zsh-autocomplete,一个叫zsh-completions,两个是类似的,我自己喜欢第一个,这个支持更丰富的提示,比如一个命令行程序,后面跟参数的时候打一个-,它会自动显示所有可用的选项。打一条命令的一部分然后按上键,它会显示所有类似于你打的东西的历史命令,以列表的形式显示,很方便

3 个赞

不错的主意,下次重做系统,试试你这个!