强大的虚拟终端zsh以及oh my zsh管理框架
2024-05-26 00:01:03  阅读数 963

什么是zsh

ZSH也称为Z Shell,是Bourne Shell(sh)的扩展版本,具有许多新功能,并支持插件和主题。 由于ZSH与Bash基于相同的外壳,因此ZSH具有许多相同的功能,并且切换起来非常容易。

zsh的安装

  • ubantu20.04下安装非常容易,直接apt install即可,然后查看系统中的全部shell中出现zsh代表安装成功
jiahui@ubuntu:~$ sudo apt install zsh

jiahui@ubuntu:~$ zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)

jiahui@ubuntu:~$ cat /etc/shells 
/bin/sh
/bin/bash
/bin/rbash
/bin/dash
/bin/zsh
/usr/bin/zsh
  • 设置zsh为默认的shell
jiahui@ubuntu:~$ chsh -s /bin/zsh 
jiahui@ubuntu:~$ reboot 
  • 查看是否已经设置称为默认的shell
jiahui@ubuntu:~$ echo $SHELL
/bin/zsh

什么是 oh my zsh

打开oh my zsh的官网,如同官网所说,Oh My Zsh是一开源的,社区驱动的框架,用于管理。

oh my zsh的安装

jiahui@ubuntu:~$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

相关的插件安装

打开配置文件,添加想要的插件,就可以进行相关插件的安装了

 ~ sudo gedit ~/.zshrc
  • 插件设置
# 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)

保存退出后在终端输入

source ~/.zshrc 

插件概述

Plugins Overview有相关的概述

插件推荐

分享出自己的plugins的设置

plugins=(
git #extras: git-extras gitfast git-flow git-flow-avh git-hubflow git-remote-branch
extract #'x' alias - swiss knife for archive extracting
z #yet another autojump
history #aliases: h for history, hsi for grepping history
rand-quote #quote function for random quotes from [https://www.quotationspage.com/random.php](https://www.quotationspage.com/random.php)
themes #ZSH theme switcher
cp #cp with progress bar (rsync)
colored-man-pages #adds colors to manpages
battery #allows see battery status in PS

# The following plug-ins need to be installed separately. Clone the corresponding git repository to the corresponding directory: ~/.oh-my-zsh/custom/plugins
zsh-syntax-highlighting #Fish shell-like syntax highlighting for Zsh(https://github.com/zsh-users/zsh-syntax-highlighting)
zsh-autosuggestions #It suggests commands as you type based on history and completions (https://github.com/zsh-users/zsh-autosuggestions)
git-open #Type git open to open the repo website (GitHub, GitLab, Bitbucket) in your browser.(https://github.com/paulirish/git-open)
)

部分插件需要单独下载到 ~/.oh-my-zsh/custom/plugins目录下


相关主题的设置

# 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="powerlevel10k/powerlevel10k"

相关主题的安装

要说到什么主题最好用,那当然是powerlevel10k。先来上一张主题的照片

安装方法,参照官网提示:

  1. 安装推荐的字体,可选,但强烈建议。
  1. 安装Powerlevel10k
  • 将仓库克隆到~/.oh-my-zsh/custom/themes
╭─     ~/.oh-my-zsh/custom/themes on    master                                                                           at   14:47:39 ─╮
╰─❯ git clone https://github.com/romkatv/powerlevel10k.git 
  • 修改zshrc配置文件
# 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="powerlevel10k/powerlevel10k"
  1. 使用exec Zsh重新启动Zsh
╭─     ~/.oh-my-zsh/custom/themes on    master                                                                     ✘ INT at   14:49:14 ─╮
╰─❯ exec zsh  
  1. 如果配置向导没有自动启动,请键入p10k configure
╭─     ~/.oh-my-zsh/custom/themes on    master                                                                     ✘ INT at   14:52:43 ─╮
╰─❯ p10k configure 
  1. 按照对应的配置向导即可完成专属自己的主题配置,如果觉得不好,请键入p10k configure重新配置

卸载

uninstall_oh_my_zsh