zsh据号称是终极shell,当然关于为什么终极我也不是很清楚,因为我也是个小白菜
但是看很多大神都在推荐这个东西,对于我来说好奇心总是会存在,那就去尝试一下吧
查看了很多的方案主要有三部分组成
1. zsh的安装与默认shell 的更改
2. zsh的配置,这个配置很多都是用的oh-my-shell
3. zsh的美化,其实这个美化也是配置的一部分只是很多人喜欢shell的原因除了好用还有一个原因就是好看,毕竟老司机都是喜欢开顺手的车也喜欢开好看的车。
4.除了车要漂亮,好开还是很重要的一点,因此插件的选配也是很重要的
那么我们就今天从这三个部分来看看如何开好这个zsh的车
最后在发车之前大家可以先看看wiki中的zsh描述这个上面的中文说明书。
1. zsh的安装与默认shell 的更改
这个部分很坑的就是,大部分的网页上都是说apt-get install这个命令来完成安装,确实这个是一个很保守的方式,但是因为保守所以落后,那个上面的版本是5.1.1(这个版本大概是15年发布的),所以并不是很喜欢这样的结果,我还是喜欢安装最新版本的。
因此呢,我们就去通过zsh的官方网站进行下载然后安装zsh
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh$ mv ~/Downloads/zsh-5.5.1.tar.gz ./
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh$ l
zsh-5.5.1.tar.gz
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh$ tar -zxvf zsh-5.5.1.tar.gz
然后我们就可以进行编译了(因为下载的是源码,当然不要因为是源码就害怕,那也就几条命令的事情)
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ ./configure
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ make
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ sudo make install
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ /usr/local/bin/zsh --version
zsh 5.5.1 (x86_64-unknown-linux-gnu)
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ which zsh
/usr/local/bin/zsh
这样我们就把zsh 安装好了,但是还没有放到可以使用的shell 名单中
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ which zsh | sudo tee -a /etc/shells
/usr/local/bin/zsh
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/usr/local/bin/zsh
在这个地方,我们因为要用管理员 权限进行补充,因此的话不和以前添加路径一样直接上一个重定向>>就添加了,所以在这个地方我们采用了tee这个命令进行添加。
接下来我们开始修改默认shell设置,然后重新登录一次就好了(一定要logout)
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ sudo chsh -s /usr/local/bin/zsh
yeyuntian@yeyuntian-rescuer-r720-15ikbn:~/zsh/zsh-5.5.1$ echo $SHELL
/bin/bash
我们logout后重新启动后就是这样了
yeyuntian-rescuer-r720-15ikbn% echo $SHELL
/usr/local/bin/zsh
说明配置完成
2.基于oh-my-zsh进行配置zsh
很惊奇的发现
yeyuntian-rescuer-r720-15ikbn% echo $PATH
/home/yeyuntian/bin:/home/yeyuntian/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
yeyuntian-rescuer-r720-15ikbn% cat ~/.zshrc
# Created by newuser for 5.1.1
我们的环境变量被修改了,而且查看~/.zhsrc 中的情况是这样的空空荡荡
所以我们需要找个框架性的东西进行布局配置,很多的教程中采用的是oh-my-zsh
首先是下载oh-my-zsh(找个太难打了我后面就简写为OMZ吧
yeyuntian-rescuer-r720-15ikbn% sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
安装完了,可以看到shell界面瞬间漂亮了一些
➜ ~ cat .zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/home/yeyuntian/.oh-my-zsh"
# 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/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
这个文件里面也有了东西,所以现在就是框架已经搭建完成。
3.OMZ的可用主题选择与安装
OMZ的可用主题有很多各种华丽的主题对应各种漂亮的shell界面
简单截个图吧:
我们选择一个安装吧:
还是觉得这个好看所以就用ys吧
进入ys的git后开始到~/.zshrc中配置就好了配置就好了
➜ ~ gedit ~/.zshrc
➜ ~ source ~/.zshrc
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~ [17:52:07]
$ ls
20180516-Firstarticle.md blog Desktop Downloads Music node-v8.11.4-linux-x64.tar.gz Pictures Public shadowsocksr-linux-client-CLI Test Videos Yeyuntianbio zsh
20180826-Gene-family-Chapter-1.md CYPdata Documents LaTex node-v8.11.4-linux-x64 package-lock.json PPT R Templates tumblr Weixin Zotero
我还是截个图吧:
最后我们还有一个事情没有干
就是把以前的哪些PATH恢复回来 很简单,就拷贝就好了
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~ [17:58:16]
$ echo $PATH
/home/yeyuntian/CYPdata/software/PfamScan:/home/yeyuntian/CYPdata/software/MCScanX:/home/yeyuntian/CYPdata/software/ParaAT1.0:/home/yeyuntian/CYPdata/software/KaKs_Calculator2.0/bin:/home/yeyuntian/CYPdata/software/circos-0.69-6/bin:/usr/local/texlive/2018/bin/x86_64-linux:/home/yeyuntian/bin:/home/yeyuntian/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/yeyuntian/CYPdata/software/ncbi-blast-2.7.1+/bin:/home/yeyuntian/CYPdata/software/ncbi-blast-2.7.1+/bin:/home/yeyuntian/node-v8.11.4-linux-x64/bin:/home/yeyuntian/node-v8.11.4-linux-x64/bin:/home/yeyuntian/CYPdata/software/iqtree-1.6.7-Linux/bin
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~ [17:58:23]
$ echo $PERL5LIB
/home/yeyuntian/CYPdata/software/PfamScan:/home/yeyuntian/CYPdata/software/PfamScan:
这个操作不再多讲,很简单。
4. 选择一些推荐的插件并安装
这个插件的目的就是有时候你输入的命令中间有错的时候会自动显示红色
安装方式如下:
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~/.oh-my-zsh/custom on git:master o [18:27:56]
$ cd $ZSH_CUSTOM/plugins/
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~/.oh-my-zsh/custom/plugins on git:master o [18:29:05]
$ pwd
/home/yeyuntian/.oh-my-zsh/custom/plugins
#~/.oh-my-zsh/custom/plugins这个文件夹是用于储存各种插件的文件夹,我们进入这个文件夹后将git仓库中的插件clone过来
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~/.oh-my-zsh/custom/plugins on git:master o [18:29:08]
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
Cloning into 'zsh-syntax-highlighting'...
remote: Counting objects: 4544, done.
remote: Total 4544 (delta 0), reused 0 (delta 0), pack-reused 4544
Receiving objects: 100% (4544/4544), 973.55 KiB | 245.00 KiB/s, done.
Resolving deltas: 100% (2984/2984), done.
Checking connectivity... done.
#然后配置到 ~/.zshrc 中就可以了
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~/.oh-my-zsh/custom/plugins on git:master o [18:31:24]
$ echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~/.oh-my-zsh/custom/plugins on git:master o [18:33:54]
$ tail ~/.zshrc
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
export PERL5LIB=/home/yeyuntian/CYPdata/software/PfamScan:/home/yeyuntian/CYPdata/software/PfamScan:
export PATH=/home/yeyuntian/CYPdata/software/PfamScan:/home/yeyuntian/CYPdata/software/MCScanX:/home/yeyuntian/CYPdata/software/ParaAT1.0:/home/yeyuntian/CYPdata/software/KaKs_Calculator2.0/bin:/home/yeyuntian/CYPdata/software/circos-0.69-6/bin:/usr/local/texlive/2018/bin/x86_64-linux:/home/yeyuntian/bin:/home/yeyuntian/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/yeyuntian/CYPdata/software/ncbi-blast-2.7.1+/bin:/home/yeyuntian/CYPdata/software/ncbi-blast-2.7.1+/bin
export PATH=/home/yeyuntian/CYPdata/software/PfamScan:/home/yeyuntian/CYPdata/software/MCScanX:/home/yeyuntian/CYPdata/software/ParaAT1.0:/home/yeyuntian/CYPdata/software/KaKs_Calculator2.0/bin:/home/yeyuntian/CYPdata/software/circos-0.69-6/bin:/usr/local/texlive/2018/bin/x86_64-linux:/home/yeyuntian/bin:/home/yeyuntian/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/yeyuntian/CYPdata/software/ncbi-blast-2.7.1+/bin:/home/yeyuntian/CYPdata/software/ncbi-blast-2.7.1+/bin:/home/yeyuntian/node-v8.11.4-linux-x64/bin:/home/yeyuntian/node-v8.11.4-linux-x64/bin
export PATH=$PATH:/home/yeyuntian/CYPdata/software/iqtree-1.6.7-Linux/bin
source /home/yeyuntian/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
#然后source一下就好了
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~/.oh-my-zsh/custom/plugins on git:master o [18:34:06]
$ source ~/.zshrc
打错了的mkdri就变成了红色的提示
这个插件是可记录你经常用的一些命令并进行提示
其他的我就赘述安装过程了,就上一个效果图
第三个插件是: 并不需要记住一长串的路径,你只需要知道你有那个模糊的文件夹 : z
第四个插件是: 反复切换文件夹的人有福了: d
第五个插件是: 拆包拆到手发软,还不如一刀切:extract
这个是自带的一个插件
只需要编辑~/.zshrc 中的plugin =()里面加入extract就可以使用了
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~/CYPdata/data/species/Rosa_chinensis/Rchinensis_Old_Blush_homozygous_genome-v2.0/genes [23:41:30]
$ x Rosa_chinensis_Old_Blush_homozygous_genome-v2.0.a1.cds.fna.gz
# yeyuntian @ yeyuntian-rescuer-r720-15ikbn in ~/CYPdata/data/species/Rosa_chinensis/Rchinensis_Old_Blush_homozygous_genome-v2.0/genes [23:41:38]
$ l
total 104M
drwxrwxr-x 2 yeyuntian yeyuntian 4.0K 9月 4 23:41 .
drwxrwxr-x 4 yeyuntian yeyuntian 4.0K 7月 18 21:38 ..
-rw-rw-r-- 1 yeyuntian yeyuntian 50M 7月 18 21:37 Rosa_chinensis_Old_Blush_homozygous_genome-v2.0.a1.cds.fna
-rw-rw-r-- 1 yeyuntian yeyuntian 38M 7月 18 21:37 Rosa_chinensis_Old_Blush_homozygous_genome-v2.0.a1.gene.fna.gz
-rw-rw-r-- 1 yeyuntian yeyuntian 7.0M 7月 18 21:37 Rosa_chinensis_Old_Blush_homozygous_genome-v2.0.a1.gff3.gz
-rw-rw-r-- 1 yeyuntian yeyuntian 1.5M 7月 18 21:37 Rosa_chinensis_Old_Blush_homozygous_genome-v2.0.a1.ncrna.fna.gz
-rw-rw-r-- 1 yeyuntian yeyuntian 8.6M 7月 18 21:37 Rosa_chinensis_Old_Blush_homozygous_genome-v2.0.a1.prot.faa.gz
x命令会自动识别然后进行解压
OK 我们今天就完成了这些配置,明天的时候我们继续对Ubuntu 进行桌面美化