简介
ohmyzsh
是Github上面目前151k⭐的项目,可以说是非常高,记录一下自己搜到的一些东西以及实际使用下来的情况。
优点
众所周知,大部分的Linux发行版的默认命令解释器是Bash。但除此之外,这个星球上的命令解释器多了去了。
几个常用的命令解释器:
Sh
Bash
Zsh
Csh
Ash
Fish
相比于默认的 Bash
,Zsh
有更多的自定义选项,并支持扩展。因此 Zsh
可以实现更强大的命令补全,命令高亮等一系列酷炫功能。
不过代价就是启动速度稍微有点慢(1秒左右,不过相比Bash
还是慢了点),而且据说语法和标准 Shell
有点区别(至少我是在使用中完全没有碰到兼容性问题)。
因此现在几乎所有的 Linux / Unix
版本的默认 Shell
仍然是 Bash
。
资源
安装
以Ubuntu
为例:
- 查看系统当前使用的
shell
$ echo $SHELL
/bin/bash
- 查看系统是否安装了
zsh
$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
默认是没有安装
zsh
。
安装zsh
apt install zsh
查看shell
列表:
$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
/bin/zsh
切换shell
为zsh
$ chsh -s /bin/zsh
Changing shell for root.
Shell changed.
这一步需要重启服务器,回来再次查看当前shell
:
$ echo $SHELL
/bin/zsh
安装ohmyzsh
基本安装
- curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
- wget
sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
- 手动安装
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh
成功界面
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ....is now installed!
Please look over the ~/.zshrc file to select plugins, themes, and options.
p.s. Follow us at https://twitter.com/ohmyzsh.
p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.
配置
主要分两大类:主题(花里胡哨的)和插件(真的很多,记都记不住)。
主题
修改主题的方法为修改 ~/.zshrc
文件:
vim ~/.zshrc
找到下面内容,替换引号内的主题名即可。
ZSH_THEME="robbyrussell"
保存后使用以下命令更新配置即可:
source ~/.zshrc
插件
修改插件和主题差不多,也是修改 ~/.zshrc
文件:
vim ~/.zshrc
找到
plugins=(git brew composer)
根据自己情况想加插件往里面加就行。插件目录为: /root/.oh-my-zsh/plugins/
介绍款比较实用的插件:zsh-syntax-highlighting
安装:
cd ~/.zshrc
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
source ./zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
或者在 /root/.oh-my-zsh/plugins/
目录:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
然后修改 ~/.zshrc
文件在 plugins=(zsh-syntax-highlighting)
中添加。
plugins=(zsh-syntax-highlighting)
还有就是比如autojump这类,自己根据需求安装。
主题预览
Github页面图片老是加载不出来,直接下载下来上传到自己服务器慢慢挑选,省的麻烦。
robbyrussell
The default that Robby Russell uses.
The rest of the themes, in alphabetical order:
A
af-magic
afowler
agnoster
alanpeabody
amuse
(You might need to install one of the patched powerline fonts for it to look the same)
apple
arrow
aussiegeek
avit
awesomepanda
B
bira
blinks
bureau
C
candy
clean
cloud
crcandy
crunch
cypher
D
dallas
darkblood
daveverwer
dieter
dogenpunk
dpoggi
dst
dstufft
duellj
E
eastwood
edvardm
emotty
essembeh
evan
F
fino-time
fino
fishy
The fish shell prompt with git support
flazz
Has git and vi-command mode support (when enabled)
fletcherm
fox
frisk
frontcube
funky
It’s funky…
fwalch
G
gallifrey
gallois
garyblessington
gentoo
geoffgarside
gianu
gnzh
gozilla
H
half-life
humza
I
imajes
intheloop
itchy
J
jaischeema
jbergantine
jispwoso
jnrowe
jonathan
josh
jreese
jtriley
juanghurtado
junkfood
K
kafeitu
kardan
kennethreitz
kolo
kphoen
L
lambda
linuxonly
(As the name states, this only works on Linux)
lukerandall
M
macovsky
maran
mgutz
mh
michelebologna
mikeh
miloshadzic
minimal
mortalscumbag
Also tells you when logged in over ssh
mrtazz
murilasso
muse
N
nanotech
nebirhos
nicoulaj
norm
O
obraun
P
peepcode
philips
pmcgee
pygmalion
R
re5et
refined
rgm
risto
rixius
rkj-repos
S
sammy
simonoff
simple
skaro
smt
Soliah
sonicradish
sorin
sporty_256
steeef
strug
sunaku
Exit status if nonzero, status & branch if git, pwd always.
sunrise
Lightweight prompt with exit status and git status consistent mode line.
superjarin
Git status, git branch, and ruby, all in a no muss, no fuss prompt! Works with RVM, chruby, and rbenv (just activate the corresponding plugin).
suvash
Username, host, directory, git branch and rvm gemset
T
takashiyoshida
terminalparty
There is a party every day.
theunraveler
Minimal, informative when it needs to be.
tjkirch
Based on dst, plus a lightning bolt and return codes.
tonotdo
trapd00r
U
UYSAL
W
wedisagree
Instructions to further customize the theme are available as comments in the theme file.
wezm
wezm+
wuffers
X
xiong-chiamiov
xiong-chiamiov-plus
Y
ys
Clean, simple, compatible and meaningful.Tested on Linux, Unix and Windows under ANSI colors. It is recommended to use with a dark background.
Z
zhann
总结
ohmyzsh
的功能真的很强大,将程序员的效率(lan duo)体现的淋漓尽致,很好,我很喜欢。