Ubuntu 下zsh的安装与配置

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的网站然后了解了一下相关的东西。
首先是下载oh-my-zsh(找个太难打了我后面就简写为OMZ吧
然后进入OMZ安装指南网站,按部就班的安装吧
yeyuntian-rescuer-r720-15ikbn% sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
安装完了,可以看到shell界面瞬间漂亮了一些
OMZ安装后漂亮了许多
➜  ~ 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界面
主题列表主题样式展示都有很多
简单截个图吧:

shell主题样式

我们选择一个安装吧:
还是觉得这个好看所以就用ys
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

我还是截个图吧:
ys截图
最后我们还有一个事情没有干
就是把以前的哪些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. 选择一些推荐的插件并安装

第一个插件是: 高亮你的世界,让错误命令Go away : zsh-syntax-highlighting
这个插件的目的就是有时候你输入的命令中间有错的时候会自动显示红色
安装方式如下:
# 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就变成了红色的提示
第二个插件是: 让熟悉的变简单,让不常用的少出现: zsh-autosuggestions
这个插件是可记录你经常用的一些命令并进行提示
其他的我就赘述安装过程了,就上一个效果图
插件对可能要输入的命令与路径进行了提示
第三个插件是: 并不需要记住一长串的路径,你只需要知道你有那个模糊的文件夹 : 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 进行桌面美化

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,706评论 4 366
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 68,002评论 1 301
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 110,462评论 0 250
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,375评论 0 216
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,763评论 3 294
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,849评论 1 224
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,033评论 2 317
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,768评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,490评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,734评论 2 253
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,204评论 1 264
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,566评论 3 260
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,227评论 3 241
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,137评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,934评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,926评论 2 283
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,774评论 2 274

推荐阅读更多精彩内容