什么是Oh My Zsh
Oh My Zsh是一款社区驱动的命令行工具,正如它的主页上说的,Oh My Zsh 是一种生活方式。它基于zsh命令行,提供了主题配置,插件机制,已经内置的便捷操作。给我们一种全新的方式使用命令行。
Oh My Zsh这个名字听起来就很有意思,它是基于zsh命令行的一个扩展工具集,提供了丰富的扩展功能。
Oh My Zsh只是一个对zsh命令行环境的配置包装框架,但它不提供命令行窗口,更不是一个独立的APP。
更详细介绍可到官网了解,Oh My Zsh官网:http://ohmyz.sh
一、安装依赖
- git
- zsh
二、下载码云安装包
wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
三、编辑install.sh
找到以下部分
# Default settings
ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}
把
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
替换为
REPO=${REPO:-mirrors/oh-my-zsh}
REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}
编辑后保存, 运行安装即可. (运行前先给install.sh权限)
chmod u+x install.sh
到这里,Oh My Zsh 就安装成功了。
四、修改仓库地址
cd ~/.oh-my-zsh
git remote set-url origin https://gitee.com/mirrors/oh-my-zsh.git
git pull
- Oh My Zsh目录结构
进入~/.oh-my-zsh目录后,看看该目录的结构
$ ls ~/.oh-my-zsh
cache custom lib log MIT-LICENSE.txt oh-my-zsh.sh plugins README.markdown templates themes tools
lib 提供了核心功能的脚本库
tools 提供安装、升级等功能的快捷工具
plugins 自带插件的存在放位置
templates 自带模板的存在放位置
themes 自带主题文件的存在放位置
custom 个性化配置目录,自安装的插件和主题可放这里
五、设置主题
安装完毕后,我们就可以使用了,咱们先来简单配置一下。
Oh My Zsh 提供了很多主题风格,我们可以根据自己的喜好,设置主题风格,主题的配置在 ~/.zshrc 文件中可以看到,用一个自己熟悉的编辑器打开这个文件,可以找到这一项:
vim ~/.zshrc
ZSH_THEME="robbyrussel"
可以看到,我们默认使用的主题叫做robbyrussel。 它的显示效果嘛,大概是这样
Oh My Zsh默认自带了一些默认主题,存放在~/.oh-my-zsh/themes目录中。我们可以查看这些主题
$ ls ~/.oh-my-zsh/themes
-rw-r--r-- 1 root root 325 Dec 28 11:56 3den.zsh-theme
-rw-r--r-- 1 root root 4.5K Dec 28 11:56 adben.zsh-theme
-rw-r--r-- 1 root root 1.5K Dec 28 11:56 af-magic.zsh-theme
-rw-r--r-- 1 root root 394 Dec 28 11:56 afowler.zsh-theme
-rw-r--r-- 1 root root 7.8K Dec 28 11:56 agnoster.zsh-theme
-rw-r--r-- 1 root root 943 Dec 28 11:56 alanpeabody.zsh-theme
-rw-r--r-- 1 root root 552 Dec 28 11:56 amuse.zsh-theme
-rw-r--r-- 1 root root 822 Dec 28 11:56 apple.zsh-theme
-rw-r--r-- 1 root root 504 Dec 28 11:56 arrow.zsh-theme
-rw-r--r-- 1 root root 325 Dec 28 11:56 aussiegeek.zsh-theme
-rw-r--r-- 1 root root 3.0K Dec 28 11:56 avit.zsh-theme
-rw-r--r-- 1 root root 748 Dec 28 11:56 awesomepanda.zsh-theme
-rw-r--r-- 1 root root 1.2K Dec 28 11:56 bira.zsh-theme
-rw-r--r-- 1 root root 979 Dec 28 11:56 blinks.zsh-theme
-rw-r--r-- 1 root root 3.3K Dec 28 11:56 bureau.zsh-theme
-rw-r--r-- 1 root root 1.3K Dec 28 11:56 candy-kingdom.zsh-theme
-rw-r--r-- 1 root root 365 Dec 28 11:56 candy.zsh-theme
-rw-r--r-- 1 root root 1.3K Dec 28 11:56 clean.zsh-theme
-rw-r--r-- 1 root root 474 Dec 28 11:56 cloud.zsh-theme
-rw-r--r-- 1 root root 372 Dec 28 11:56 crcandy.zsh-theme
-rw-r--r-- 1 root root 1.7K Dec 28 11:56 crunch.zsh-theme
-rw-r--r-- 1 root root 262 Dec 28 11:56 cypher.zsh-theme
-rw-r--r-- 1 root root 1.4K Dec 28 11:56 dallas.zsh-theme
-rw-r--r-- 1 root root 632 Dec 28 11:56 darkblood.zsh-theme
-rw-r--r-- 1 root root 308 Dec 28 11:56 daveverwer.zsh-theme
-rw-r--r-- 1 root root 2.0K Dec 28 11:56 dieter.zsh-theme
-rw-r--r-- 1 root root 3.2K Dec 28 11:56 dogenpunk.zsh-theme
-rw-r--r-- 1 root root 580 Dec 28 11:56 dpoggi.zsh-theme
-rw-r--r-- 1 root root 648 Dec 28 11:56 dstufft.zsh-theme
-rw-r--r-- 1 root root 510 Dec 28 11:56 dst.zsh-theme
-rw-r--r-- 1 root root 544 Dec 28 11:56 duellj.zsh-theme
-rw-r--r-- 1 root root 891 Dec 28 11:56 eastwood.zsh-theme
-rw-r--r-- 1 root root 365 Dec 28 11:56 edvardm.zsh-theme
-rw-r--r-- 1 root root 4.0K Dec 28 11:56 emotty.zsh-theme
-rw-r--r-- 1 root root 1.2K Dec 28 11:56 essembeh.zsh-theme
-rw-r--r-- 1 root root 51 Dec 28 11:56 evan.zsh-theme
-rw-r--r-- 1 root root 1.3K Dec 28 11:56 fino-time.zsh-theme
-rw-r--r-- 1 root root 1.5K Dec 28 11:56 fino.zsh-theme
-rw-r--r-- 1 root root 1.2K Dec 28 11:56 fishy.zsh-theme
-rw-r--r-- 1 root root 648 Dec 28 11:56 flazz.zsh-theme
-rw-r--r-- 1 root root 1.2K Dec 28 11:56 fletcherm.zsh-theme
-rw-r--r-- 1 root root 547 Dec 28 11:56 fox.zsh-theme
-rw-r--r-- 1 root root 504 Dec 28 11:56 frisk.zsh-theme
-rw-r--r-- 1 root root 525 Dec 28 11:56 frontcube.zsh-theme
-rw-r--r-- 1 root root 603 Dec 28 11:56 funky.zsh-theme
-rw-r--r-- 1 root root 334 Dec 28 11:56 fwalch.zsh-theme
-rw-r--r-- 1 root root 423 Dec 28 11:56 gallifrey.zsh-theme
-rw-r--r-- 1 root root 884 Dec 28 11:56 gallois.zsh-theme
-rw-r--r-- 1 root root 312 Dec 28 11:56 garyblessington.zsh-theme
-rw-r--r-- 1 root root 280 Dec 28 11:56 gentoo.zsh-theme
-rw-r--r-- 1 root root 258 Dec 28 11:56 geoffgarside.zsh-theme
-rw-r--r-- 1 root root 363 Dec 28 11:56 gianu.zsh-theme
-rw-r--r-- 1 root root 937 Dec 28 11:56 gnzh.zsh-theme
-rw-r--r-- 1 root root 614 Dec 28 11:56 gozilla.zsh-theme
-rw-r--r-- 1 root root 2.8K Dec 28 11:56 half-life.zsh-theme
-rw-r--r-- 1 root root 1000 Dec 28 11:56 humza.zsh-theme
-rw-r--r-- 1 root root 107 Dec 28 11:56 imajes.zsh-theme
-rw-r--r-- 1 root root 1021 Dec 28 11:56 intheloop.zsh-theme
-rw-r--r-- 1 root root 602 Dec 28 11:56 itchy.zsh-theme
-rw-r--r-- 1 root root 561 Dec 28 11:56 jaischeema.zsh-theme
-rw-r--r-- 1 root root 363 Dec 28 11:56 jbergantine.zsh-theme
-rw-r--r-- 1 root root 527 Dec 28 11:56 jispwoso.zsh-theme
-rw-r--r-- 1 root root 1.1K Dec 28 11:56 jnrowe.zsh-theme
-rw-r--r-- 1 root root 4.1K Dec 28 11:56 jonathan.zsh-theme
-rw-r--r-- 1 root root 1.2K Dec 28 11:56 josh.zsh-theme
-rw-r--r-- 1 root root 487 Dec 28 11:56 jreese.zsh-theme
-rw-r--r-- 1 root root 171 Dec 28 11:56 jtriley.zsh-theme
-rw-r--r-- 1 root root 1.3K Dec 28 11:56 juanghurtado.zsh-theme
-rw-r--r-- 1 root root 1.2K Dec 28 11:56 junkfood.zsh-theme
-rw-r--r-- 1 root root 416 Dec 28 11:56 kafeitu.zsh-theme
-rw-r--r-- 1 root root 266 Dec 28 11:56 kardan.zsh-theme
-rw-r--r-- 1 root root 615 Dec 28 11:56 kennethreitz.zsh-theme
-rw-r--r-- 1 root root 558 Dec 28 11:56 kiwi.zsh-theme
-rw-r--r-- 1 root root 689 Dec 28 11:56 kolo.zsh-theme
-rw-r--r-- 1 root root 1.5K Dec 28 11:56 kphoen.zsh-theme
-rw-r--r-- 1 root root 145 Dec 28 11:56 lambda.zsh-theme
-rw-r--r-- 1 root root 2.0K Dec 28 11:56 linuxonly.zsh-theme
-rw-r--r-- 1 root root 904 Dec 28 11:56 lukerandall.zsh-theme
lrwxrwxrwx 1 root root 18 Dec 28 11:56 macovsky-ruby.zsh-theme -> macovsky.zsh-theme
-rw-r--r-- 1 root root 472 Dec 28 11:56 macovsky.zsh-theme
-rw-r--r-- 1 root root 316 Dec 28 11:56 maran.zsh-theme
-rw-r--r-- 1 root root 256 Dec 28 11:56 mgutz.zsh-theme
-rw-r--r-- 1 root root 1.6K Dec 28 11:56 mh.zsh-theme
-rw-r--r-- 1 root root 2.8K Dec 28 11:56 michelebologna.zsh-theme
-rw-r--r-- 1 root root 857 Dec 28 11:56 mikeh.zsh-theme
-rw-r--r-- 1 root root 359 Dec 28 11:56 miloshadzic.zsh-theme
-rw-r--r-- 1 root root 904 Dec 28 11:56 minimal.zsh-theme
-rw-r--r-- 1 root root 811 Dec 28 11:56 mira.zsh-theme
-rw-r--r-- 1 root root 1.3K Dec 28 11:56 mlh.zsh-theme
-rw-r--r-- 1 root root 2.2K Dec 28 11:56 mortalscumbag.zsh-theme
-rw-r--r-- 1 root root 378 Dec 28 11:56 mrtazz.zsh-theme
-rw-r--r-- 1 root root 631 Dec 28 11:56 murilasso.zsh-theme
-rw-r--r-- 1 root root 770 Dec 28 11:56 muse.zsh-theme
-rw-r--r-- 1 root root 258 Dec 28 11:56 nanotech.zsh-theme
-rw-r--r-- 1 root root 988 Dec 28 11:56 nebirhos.zsh-theme
-rw-r--r-- 1 root root 1.7K Dec 28 11:56 nicoulaj.zsh-theme
-rw-r--r-- 1 root root 377 Dec 28 11:56 norm.zsh-theme
-rw-r--r-- 1 root root 534 Dec 28 11:56 obraun.zsh-theme
-rw-r--r-- 1 root root 1.2K Dec 28 11:56 peepcode.zsh-theme
-rw-r--r-- 1 root root 1.3K Dec 28 11:56 philips.zsh-theme
-rw-r--r-- 1 root root 1.3K Dec 28 11:56 pmcgee.zsh-theme
-rw-r--r-- 1 root root 1.8K Dec 28 11:56 pygmalion-virtualenv.zsh-theme
-rw-r--r-- 1 root root 1.1K Dec 28 11:56 pygmalion.zsh-theme
-rw-r--r-- 1 root root 1.6K Dec 28 11:56 random.zsh-theme
-rw-r--r-- 1 root root 680 Dec 28 11:56 re5et.zsh-theme
-rw-r--r-- 1 root root 3.3K Dec 28 11:56 refined.zsh-theme
-rw-r--r-- 1 root root 268 Dec 28 11:56 rgm.zsh-theme
-rw-r--r-- 1 root root 311 Dec 28 11:56 risto.zsh-theme
-rw-r--r-- 1 root root 789 Dec 28 11:56 rixius.zsh-theme
-rw-r--r-- 1 root root 1.9K Dec 28 11:56 rkj-repos.zsh-theme
-rw-r--r-- 1 root root 557 Dec 28 11:56 rkj.zsh-theme
-rw-r--r-- 1 root root 344 Dec 28 11:56 robbyrussell.zsh-theme
-rw-r--r-- 1 root root 191 Dec 28 11:56 sammy.zsh-theme
-rw-r--r-- 1 root root 3.4K Dec 28 11:56 simonoff.zsh-theme
-rw-r--r-- 1 root root 230 Dec 28 11:56 simple.zsh-theme
-rw-r--r-- 1 root root 325 Dec 28 11:56 skaro.zsh-theme
-rw-r--r-- 1 root root 3.3K Dec 28 11:56 smt.zsh-theme
-rw-r--r-- 1 root root 3.3K Dec 28 11:56 Soliah.zsh-theme
-rw-r--r-- 1 root root 1.3K Dec 28 11:56 sonicradish.zsh-theme
-rw-r--r-- 1 root root 1.5K Dec 28 11:56 sorin.zsh-theme
-rw-r--r-- 1 root root 589 Dec 28 11:56 sporty_256.zsh-theme
-rw-r--r-- 1 root root 2.8K Dec 28 11:56 steeef.zsh-theme
-rw-r--r-- 1 root root 918 Dec 28 11:56 strug.zsh-theme
-rw-r--r-- 1 root root 748 Dec 28 11:56 sunaku.zsh-theme
-rw-r--r-- 1 root root 2.9K Dec 28 11:56 sunrise.zsh-theme
-rw-r--r-- 1 root root 734 Dec 28 11:56 superjarin.zsh-theme
-rw-r--r-- 1 root root 661 Dec 28 11:56 suvash.zsh-theme
-rw-r--r-- 1 root root 788 Dec 28 11:56 takashiyoshida.zsh-theme
-rw-r--r-- 1 root root 356 Dec 28 11:56 terminalparty.zsh-theme
-rw-r--r-- 1 root root 579 Dec 28 11:56 theunraveler.zsh-theme
-rw-r--r-- 1 root root 514 Dec 28 11:56 tjkirch_mod.zsh-theme
-rw-r--r-- 1 root root 516 Dec 28 11:56 tjkirch.zsh-theme
-rw-r--r-- 1 root root 1.2K Dec 28 11:56 tonotdo.zsh-theme
-rw-r--r-- 1 root root 3.6K Dec 28 11:56 trapd00r.zsh-theme
-rw-r--r-- 1 root root 4.4K Dec 28 11:56 wedisagree.zsh-theme
-rw-r--r-- 1 root root 366 Dec 28 11:56 wezm.zsh-theme
-rw-r--r-- 1 root root 443 Dec 28 11:56 wezm+.zsh-theme
-rw-r--r-- 1 root root 333 Dec 28 11:56 wuffers.zsh-theme
-rw-r--r-- 1 root root 574 Dec 28 11:56 xiong-chiamiov-plus.zsh-theme
-rw-r--r-- 1 root root 554 Dec 28 11:56 xiong-chiamiov.zsh-theme
-rw-r--r-- 1 root root 1.7K Dec 28 11:56 ys.zsh-theme
-rw-r--r-- 1 root root 686 Dec 28 11:56 zhann.zsh-theme
怎么样,默认主题的数量相当多吧,这就是社区驱动的力量。
这么多的主题可以满足你的各种偏好了,我们只需在./zshrc文件中配置需要的主题即可,比如我们想用lambda.zsh-theme这个主题,我们只要这样配置
ZSH_THEME="lambda"
然后保存这个文件文件,再打开一个新的命令行窗口即可看到效果了。那么这么多的主题如何快速找到哪些是我们喜欢的呢,我们还可以这样设置
ZSH_THEME="random"
我们将主题设置为随机,这样在我们每次打开命令行窗口的时候,都会随机在默认主题中选择一个。这样我们如果觉得当前的主题比较喜欢,可以直接使用 echo 命令输出当前主题的名称
$ echo $ZSH_THEME
然后再将他设置到配置文件中即可。
如果这些默认主题还不能满足你的需要,我们还可以到这里找到更多的主题
https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes
https://github.com/unixorn/awesome-zsh-plugins#themes
六、启用插件
Oh My Zsh 默认自带了一些默认主题,存放在~/.oh-my-zsh/plugins目录中。我们可以查看这些插件
$ ls ~/.oh-my-zsh/plugins
adb brew coffee dirpersist fastfile gitignore httpie last-working-dir nanoc pod rebar sprunge terminitor vault zeus
ant brew-cask colemak django fbterm git-prompt iwhois lein nmap postgres redis-cli ssh-agent terraform vim-interaction zsh-navigation-tools
apache2-macports bundler colored-man-pages dnf fedora git-remote-branch jake-node lighthouse node pow repo stack textastic vi-mode zsh_reload
archlinux bwana colorize docker forklift glassfish jhbuild lol npm powder rsync sublime textmate virtualenv
asdf cabal command-not-found docker-compose frontend-search gnu-utils jira macports nvm powify ruby sudo thefuck virtualenvwrapper
autoenv cake common-aliases emacs gas go jruby man nyan profiles rvm supervisor themes vundle
autojump cakephp3 compleat ember-cli geeknote golang jsontools marked2 osx pyenv safe-paste suse thor wakeonlan
autopep8 capistrano composer emoji gem gpg-agent jump mercurial pass pylint sbt svn tmux wd
aws cask copydir emoji-clock git gradle kate meteor paver python scala svn-fast-info tmux-cssh web-search
battery catimg copyfile emotty git-extras grails kitchen mix pep8 rails scd symfony tmuxinator wp-cli
bbedit celery cp encode64 gitfast grunt knife mix-fast per-directory-history rake screen symfony2 torrent xcode
bgnotify chruby cpanm extract git-flow gulp knife_ssh mosh perl rake-fast scw systemadmin tugboat yii
boot2docker chucknorris debian fabric git-flow-avh heroku laravel mvn phing rand-quote sfffe systemd ubuntu yii2
bower cloudapp dircycle fancy-ctrl-z github history laravel4 mysql-macports pip rbenv singlechar taskwarrior urltools yum
branch codeclimate dirhistory fasd git-hubflow history-substring-search laravel5 n98-magerun pj rbfu spring terminalapp vagrant z
Oh My Zsh默认是只启用git插件(在~/.zshrc文件中)
plugins=(git)
如需启用更多插件,可加入需启用插件的名称。如下
plugins=(git wd web-search history history-substring-search)
推荐几个好用插件
zsh-history-substring-search
https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/history-substring-search
zsh-syntax-highlighting
https://github.com/zsh-users/zsh-syntax-highlighting
zsh-autosuggestions
https://github.com/zsh-users/zsh-autosuggestions
更多插件可参考
https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
https://github.com/unixorn/awesome-zsh-plugins
https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins-Overview
一些小技巧
给history命令增加时间
.zshrc中加入以下行
$ vim ~/.zshrc
HIST_STAMPS="yyyy-mm-dd"
source ~/.zshrc
如果没用oh my zsh的话可用如下alias
$ alias history='fc -il 1'
七、更新oh-my-zsh
设置自动更新oh-my-zsh
默认情况下,当oh-my-zsh有更新时,都会给你提示。如果希望让oh-my-zsh自动更新,在~/.zshrc 中添加下面这句
DISABLE_UPDATE_PROMPT=true
要手动更新,可以执行
$ upgrade_oh_my_zsh
八、卸载oh my zsh
直接在终端中,运行uninstall_oh_my_zsh既可以卸载。