Mac安裝zsh工具

Zsh默認不兼容Bash,不過Zsh實現中包含了一個屌炸天的仿真模式(emulation mode)支持對兩種主流的Bourne衍生版shell(bash、ksh)和C shell的仿真(csh的支持并不完整)。在Bash的仿真模式下,可以使用與Bash相同的語法和命令集合,從而達到近乎完全兼容的目的。

為了激活對Bash的仿真,需要顯式執(zhí)行

$ emulate bash

等效于

$ emulate sh

更詳細介紹可到官網了解,zsh官網:http://www.zsh.org/

安裝

Redhat/Centos

$ yum install zsh

Debian/Ubuntu

$ apt-get install zsh

設置默認shell為zsh

$ chsh -s $(which zsh)

完成后可以使用下面這條命令檢查是否設置成功

$ echo $SHELL

什么是Oh My Zsh

Oh My Zsh是一款社區(qū)驅動的命令行工具,正如它的主頁上說的,Oh My Zsh 是一種生活方式。它基于zsh命令行,提供了主題配置,插件機制,已經內置的便捷操作。給我們一種全新的方式使用命令行。

Oh My Zsh這個名字聽起來就很有意思,它是基于zsh命令行的一個擴展工具集,提供了豐富的擴展功能。

Oh My Zsh只是一個對zsh命令行環(huán)境的配置包裝框架,但它不提供命令行窗口,更不是一個獨立的APP。

更詳細介紹可到官網了解,Oh My Zsh官網:http://ohmyz.sh

安裝Oh My Zsh

前提條件:必須已安裝ZSH

我們可以在命令行中輸入這個命令來查看我們的電腦上是否安裝了zsh命令行

$ zsh --version

如果安裝了,這個命令就會輸出zsh當前的版本號。確定 zsh 已經安裝后,我們就可以繼續(xù)安裝Oh My Zsh了。

安裝Oh My Zsh

Oh My Zsh 的安裝方式非常簡單,可以通過curl或wget的方式,用一條命令即可安裝。

curl 方式

$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

wget 方式

$ sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

安裝過程中輸出如下

Cloning Oh My Zsh... Cloning into '/root/.oh-my-zsh'... remote: Counting objects: 712, done. remote: Compressing objects: 100% (584/584), done. remote: Total 712 (delta 15), reused 522 (delta 4), pack-reused 0 Receiving objects: 100% (712/712), 443.58 KiB | 27.00 KiB/s, done. Resolving deltas: 100% (15/15), done. Checking connectivity... done. Looking for an existing zsh config... Using the Oh My Zsh template file and adding it to ~/.zshrc Copying your current PATH and adding it to the end of ~/.zshrc for you. Time to change your default shell to zsh!? ? ? ? __? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? __ ____? / /_? ? ____ ___? __? __? ____? _____/ /_ / __ \/ __ \? / __ `__ \/ / / /? /_? / / ___/ __ \ / /_/ / / / /? / / / / / / /_/ /? ? / /_(__? ) / / / \____/_/ /_/? /_/ /_/ /_/\__, /? ? /___/____/_/ /_/? ? ? ? ? ? ? ? ? ? ? /____/? ? ? ? ? ? ? ? ? ? ? ....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.

到這里,Oh My Zsh 就安裝成功了。

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 文件中可以看到,用一個自己熟悉的編輯器打開這個文件,可以找到這一項:

ZSH_THEME="robbyrussel"

可以看到,我們默認使用的主題叫做robbyrussel。 它的顯示效果嘛,大概是這樣

Oh My Zsh默認自帶了一些默認主題,存放在~/.oh-my-zsh/themes目錄中。我們可以查看這些主題

$ ls ~/.oh-my-zsh/themes 3den.zsh-theme? ? ? ? ? ? ? ? essembeh.zsh-theme? ? ? ? ? ? junkfood.zsh-theme? ? ? ? ? ? rgm.zsh-theme Soliah.zsh-theme? ? ? ? ? ? ? evan.zsh-theme? ? ? ? ? ? ? ? kafeitu.zsh-theme? ? ? ? ? ? risto.zsh-theme adben.zsh-theme? ? ? ? ? ? ? example.zsh-theme? ? ? ? ? ? kardan.zsh-theme? ? ? ? ? ? ? rixius.zsh-theme af-magic.zsh-theme? ? ? ? ? ? fino-time.zsh-theme? ? ? ? ? kennethreitz.zsh-theme? ? ? ? rkj-repos.zsh-theme afowler.zsh-theme? ? ? ? ? ? fino.zsh-theme? ? ? ? ? ? ? ? kiwi.zsh-theme? ? ? ? ? ? ? ? rkj.zsh-theme agnoster.zsh-theme? ? ? ? ? ? fishy.zsh-theme? ? ? ? ? ? ? kolo.zsh-theme? ? ? ? ? ? ? ? robbyrussell.zsh-theme alanpeabody.zsh-theme? ? ? ? flazz.zsh-theme? ? ? ? ? ? ? kphoen.zsh-theme? ? ? ? ? ? ? sammy.zsh-theme amuse.zsh-theme? ? ? ? ? ? ? fletcherm.zsh-theme? ? ? ? ? lambda.zsh-theme? ? ? ? ? ? ? simonoff.zsh-theme apple.zsh-theme? ? ? ? ? ? ? fox.zsh-theme? ? ? ? ? ? ? ? linuxonly.zsh-theme? ? ? ? ? simple.zsh-theme arrow.zsh-theme? ? ? ? ? ? ? frisk.zsh-theme? ? ? ? ? ? ? lukerandall.zsh-theme? ? ? ? skaro.zsh-theme ....

怎么樣,默認主題的數量相當多吧,這就是社區(qū)驅動的力量。

這么多的主題可以滿足你的各種偏好了,我們只需在./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插件

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

要手動更新,可以執(zhí)行

$ upgrade_oh_my_zsh

卸載oh my zsh

直接在終端中,運行uninstall_oh_my_zsh既可以卸載。

參考文檔

http://www.google.com

http://ohmyz.sh/

http://swiftcafe.io/2015/10/31/cafe-time-omz/

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容