新时代终端Zsh

2023年 8月 29日 59.1k 0

安装 Zsh

  • 安装 Zsh:
 [root@linux ~]# yum install -y zsh
  • 查看 Zsh 版本:
 [root@linux ~]# zsh --version
 zsh 5.5.1 (x86_64-redhat-linux-gnu)
  • 配置 Zsh:对中文显示等进行简单的设置
 # 编辑配置文件,行尾加入以下三行
 [root@linux ~]# vim ~/.zshrc
 export LC_ALL=en_US.UTF-8
 export LANG=en_US.UTF-8
 source /etc/profile
 
 # 保存并更新
 [root@linux ~]# source ~/.zshrc

安装 Oh-My-Zsh

  • 下载 Oh-My-Zsh 安装脚本:
[root@linux ~]# wget https://github.moeyy.xyz/https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
  • 安装 Oh-My-Zsh:执行 Oh-My-Zsh 的安装脚本
[root@linux ~]# bash install.sh
Cloning Oh My Zsh...
remote: Enumerating objects: 1345, done.
remote: Counting objects: 100% (1345/1345), done.
remote: Compressing objects: 100% (1296/1296), done.
remote: Total 1345 (delta 27), reused 1160 (delta 25), pack-reused 0
Receiving objects: 100% (1345/1345), 2.00 MiB | 49.00 KiB/s, done.
Resolving deltas: 100% (27/27), done.
From https://github.com/ohmyzsh/ohmyzsh
 * [new branch]      master     -> origin/master
branch 'master' set up to track 'origin/master'.
Already on 'master'
/root

Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to /root/.zshrc.

Time to change your default shell to zsh:						# 是否将 zsh 设置为默认的 SHELL
Do you want to change your default shell to zsh? [Y/n] Y
Changing your shell to /usr/bin/zsh...
Changing shell for root.
Shell changed.
Shell successfully changed to '/usr/bin/zsh'.

         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ / __    / __ `__ / / / /  /_  / / ___/ __ 
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
____/_/ /_/  /_/ /_/ /_/__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!


Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options.

• Follow us on Twitter: https://twitter.com/ohmyzsh
• Join our Discord community: https://discord.gg/ohmyzsh
• Get stickers, t-shirts, coffee mugs and more: https://shop.planetargon.com/collections/oh-my-zsh

安装插件

Zsh 有很多好玩的插件:如常用的语法高亮,历史命令提示,和路径补全等。安装的插件默认在 ~/.oh-my-zsh/custom/plugins 目录

命令行语法高亮插件

  • 克隆 "命令行语法高亮" 插件仓库:
[root@linux ~]# git clone https://github.moeyy.xyz/https://github.com/zsh-users/zsh-syntax-highlighting.git
  • 移动 "命令行语法高亮" 到 Oh-My-Zsh 插件目录:
[root@linux ~]# mv zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/
  • 配置 "命令行语法高亮" 插件:编辑 .zshrc 文件的 plugins=() 选项
[root@linux ~]# vim ~/.zshrc
plugins=(
     git
     zsh-syntax-highlighting
)
  • 生效 "命令行语法高亮" 插件:
[root@linux ~]# source ~/.zshrc

命令补全插件

  • 克隆 "命令补全" 插件仓库:
[root@linux ~]# git clone https://github.moeyy.xyz/https://github.com/zsh-users/zsh-autosuggestions.git
  • 移动 "命令补全" 到 Oh-My-Zsh 插件目录:
[root@linux ~]# mv mv zsh-autosuggestions/ ~/.oh-my-zsh/custom/plugins/
  • 配置 "命令补全" 插件:编辑 .zshrc 文件的 plugins=() 选项
[root@linux ~]# vim ~/.zshrc
plugins=(
     git
     zsh-syntax-highlighting
     zsh-autosuggestions
)
  • 生效 "命令补全" 插件:
[root@linux ~]# source ~/.zshrc

更改主题

Oh-My-Zsh 自带很多主题,全部放在 ~/.oh-my-zsh/themes 目录下,可以随意更换。更换主题只需要更换 .zshrc 文件中的 ZSH_THEME="主题名称" 即可

  • 更换 Zsh 主题:默认的主题是 robbyrussel,将其更换为 agnoster
[root@linux ~]# vim ~/.zshrc
ZSH_THEME="agnoster"
  • 生效主题配置:
[root@linux ~]# source ~/.zshrc
  • 效果如下:

Snipaste_2023-08-28_20-22-54.png

切换回 Bash

[root@linux ~]# chsh -s /bin/bash

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论