侧边栏壁纸
博主头像
duan6666的blog

行动起来,活在当下

  • 累计撰写 7 篇文章
  • 累计创建 4 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

安利一个好看的shell

duan6666
2024-04-10 / 0 评论 / 0 点赞 / 54 阅读 / 0 字
温馨提示:
本文最后更新于2025-01-02,若内容或图片失效,请留言反馈。 部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1:前言

前段时间在B站刷到了关于zsh视频,立刻就被其中的开箱即用的命令行补全功能吸引了
同时也了解到on my zsh这个东西,这玩意给zsh做了个拓展,能让zsh使用主题外观和插件还可以定制其中的设置
上手安装使用了下这个既好看又能自动补全命令的shell,便立刻想安利一下了

2:安装环境介绍

本机是Windows11家庭普通版(64位),而linux端是使用的家里的老电脑,安装的ubuntu
安装的前置条件:系统为类 Unix 操作系统如 MacOS、Linux、BSD

3:安装ZSH

先使用apt更新软件包

apt update

稍等片刻

root@duan6666:~# apt update
命中:1 http://archive.ubuntu.com/ubuntu mantic InRelease
获取:2 http://archive.ubuntu.com/ubuntu mantic-updates InRelease [109 kB]
获取:3 http://archive.ubuntu.com/ubuntu mantic-security InRelease [109 kB]                                                                                      
获取:4 http://archive.ubuntu.com/ubuntu mantic-updates/main amd64 Packages [360 kB]                                                                             
获取:5 http://archive.ubuntu.com/ubuntu mantic-updates/main Translation-en [99.4 kB]                                                                            
获取:6 http://archive.ubuntu.com/ubuntu mantic-updates/restricted amd64 Packages [287 kB]                                                                       
获取:7 http://archive.ubuntu.com/ubuntu mantic-updates/restricted Translation-en [48.8 kB]                                                                      
获取:8 http://archive.ubuntu.com/ubuntu mantic-updates/universe amd64 Packages [303 kB]                                                                         
获取:9 http://archive.ubuntu.com/ubuntu mantic-updates/universe Translation-en [125 kB]                                                                         
获取:10 http://archive.ubuntu.com/ubuntu mantic-updates/multiverse amd64 Packages [8,568 B]                                                                     
获取:11 http://archive.ubuntu.com/ubuntu mantic-updates/multiverse Translation-en [2,824 B]                                                                     
获取:12 http://archive.ubuntu.com/ubuntu mantic-security/main amd64 Packages [310 kB]                                                                           
获取:13 http://archive.ubuntu.com/ubuntu mantic-security/main Translation-en [82.5 kB]                                                                          
获取:14 http://archive.ubuntu.com/ubuntu mantic-security/universe amd64 Packages [268 kB]                                                                       
获取:15 http://archive.ubuntu.com/ubuntu mantic-security/universe Translation-en [112 kB]                                                                       
已下载 2,224 kB,耗时 9秒 (261 kB/s)                                                                                                                            
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
有 80 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。

使用apt安装zsh curl wget git

apt install zsh curl wget git -y

稍等片刻

root@duan6666:~# apt install zsh curl wget git -y
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
建议安装:
  git-daemon-run | git-daemon-sysvinit git-doc git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn zsh-doc
下列【新】软件包将被安装:
  curl git wget zsh
升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 76 个软件包未被升级。
需要下载 4,941 kB 的归档。
解压缩后会消耗 25.7 MB 的额外空间。
获取:1 http://archive.ubuntu.com/ubuntu mantic/main amd64 wget amd64 1.21.3-1ubuntu1 [334 kB]
获取:2 http://archive.ubuntu.com/ubuntu mantic-updates/main amd64 curl amd64 8.2.1-1ubuntu3.3 [216 kB]                                                          
获取:3 http://archive.ubuntu.com/ubuntu mantic/main amd64 git amd64 1:2.40.1-1ubuntu1 [3,583 kB]                                                                
获取:4 http://archive.ubuntu.com/ubuntu mantic/main amd64 zsh amd64 5.9-5ubuntu1 [808 kB]                                                                       
已下载 4,941 kB,耗时 8秒 (626 kB/s)                                                                                                                            
正在选中未选择的软件包 wget。
(正在读取数据库 ... 系统当前共安装有 21724 个文件和目录。)
准备解压 .../wget_1.21.3-1ubuntu1_amd64.deb  ...
正在解压 wget (1.21.3-1ubuntu1) ...
正在选中未选择的软件包 curl。
准备解压 .../curl_8.2.1-1ubuntu3.3_amd64.deb  ...
正在解压 curl (8.2.1-1ubuntu3.3) ...
正在选中未选择的软件包 git。
准备解压 .../git_1%3a2.40.1-1ubuntu1_amd64.deb  ...
正在解压 git (1:2.40.1-1ubuntu1) ...
正在选中未选择的软件包 zsh。
准备解压 .../zsh_5.9-5ubuntu1_amd64.deb  ...
正在解压 zsh (5.9-5ubuntu1) ...
正在设置 wget (1.21.3-1ubuntu1) ...
正在设置 git (1:2.40.1-1ubuntu1) ...
正在设置 curl (8.2.1-1ubuntu3.3) ...
正在设置 zsh (5.9-5ubuntu1) ...
正在处理用于 man-db (2.11.2-3) 的触发器 ...
正在处理用于 debianutils (5.8-1) 的触发器 ...
正在处理用于 install-info (7.0.3-2) 的触发器 ...

此时zsh便已经安装完成了,使用zsh切换到zsh

zsh
root@duan6666:~# zsh
duan6666# 

4:安装oh my zsh

使用curl

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

使用wget

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

我这边使用的curl安装

duan6666#sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Cloning Oh My Zsh...
remote: Enumerating objects: 1389, done.
remote: Counting objects: 100% (1389/1389), done.
remote: Compressing objects: 100% (1336/1336), done.
remote: Total 1389 (delta 31), reused 1077 (delta 25), pack-reused 0
接收对象中: 100% (1389/1389), 3.20 MiB | 1.07 MiB/s, 完成.
处理 delta 中: 100% (31/31), 完成.
来自 https://github.com/ohmyzsh/ohmyzsh
 * [新分支]          master     -> origin/master
分支 'master' 设置为跟踪 'origin/master'。
已经位于 'master'
/root

Looking for an existing zsh config...
Found /root/.zshrc. Backing up to /root/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to /root/.zshrc.

Time to change your default shell to zsh:
Do you want to change your default shell to zsh? [Y/n]

按y把默认shell改为zsh

Do you want to change your default shell to zsh? [Y/n] y
Changing your shell to /usr/bin/zsh...
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

➜  ~

或使用chsh命令改变默认shell

chsh -s /bin/zsh

再次登录时,zsh的界面已经变成了新样式

➜  ~

5:安装主题

这时便可以在.zshrc文件里面选择一些自带的插件和主题
但我比较喜欢p10k(powerlevel10k)
github拉取文件

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k

稍等

➜  ~ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
正克隆到 '/root/powerlevel10k'...
remote: Enumerating objects: 92, done.
remote: Counting objects: 100% (92/92), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 92 (delta 18), reused 76 (delta 13), pack-reused 0
接收对象中: 100% (92/92), 348.68 KiB | 761.00 KiB/s, 完成.
处理 delta 中: 100% (18/18), 完成.

此时便拉取完成,选择该主题

echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc

再次登入时便会开始个性化配置

zsh

接下来的配置便通过翻译,自行配置吧

6:安装插件

安装语法高亮插件

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

安装自动补全插件

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

启用插件

vi ~/.zshrc

使用数字键旁边的←↑↓→将光标移动到plugins那一行对应的位置
i 键键入新下载的插件至plugins=(git)中

plugins=(git)
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)

若是输错可以用Delete删除,或按下esc,输入:q!强制退出并不保存
按下键盘右上角的esc,键入:wq保存并退出
再次登入时便能体验到插件带来的便捷

0

评论区