什麼是Zsh html
Zsh和bash同樣,是一種Unix shell,但大多數Linux發行版本都默認使用bash shell。但Zsh有強大的自動補全參數、文件名、等功能和強大的自定義配置功能。python
替換Mac的bashlinux
Zsh雖然功能強大,但剛上手配置比較麻煩。別擔憂,Github已經有開源項目oh-my-zsh。按照官方的文檔安裝,很是簡單。git
1、使用curl自動安裝github
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | shdocker
2、手動安裝shell
1.使用git clone 項目 vim
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zshruby
2.備份~/.zshrc文件bash
cp ~/.zshrc ~/.zshrc.orig
3.建立新的zsh配置文件
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
4.設置zsh爲默認shell
chsh -s /bin/zsh
5.重啓Terminal或新建一個Terminal就能夠看到效果了
接下來配置適合本身Zsh
1.主題修改,我比較喜歡前面是$符號,因此選擇了steeef這款主題
$ vim ~/.zshrc
配置文件裏找到:
ZSH_THEME="robbyrussell"
修改成:
ZSH_THEME="steeef"
這裏是官方提供的各類主題,有截圖參考oh-my-zsh-themes
2.插件的選擇,支持git、brew、vi、osx等插件,具體請查看這裏oh-my-zsh-plugins
3.按兩下tab會有驚喜,好比git
選擇oh-my-zsh
oh-my-zsh是基於zsh的功能作了一個擴展,方便的插件管理、主題自定義,以及漂亮的自動完成效果。
在Github上找關於zsh的項目時發現的,試用了一下以爲很方便,不用像上面文章裏面提到的那麼複雜,配置一些插件的名稱便可使用相應的功能。
官網:https://github.com/robbyrussell/oh-my-zsh
評價:https://github.com/robbyrussell/oh-my-zsh/wiki/Testimonials
截圖欣賞(Git插件):

再來一個自動完成:

定義hash快速進入目錄:
在~/.zshrc中定義:
hash -d blog="/home/henryyan/work/blog/henryyan.github.com"

安裝oh-my-zsh
進入Github的oh-my-zsh主頁 https://github.com/robbyrussell/oh-my-zsh ,在下面有詳細的安裝方式。
自定義主題
在 https://github.com/robbyrussell/oh-my-zsh/wiki/themes 裏面有不少主題能夠選擇,安裝後只須要修改~/.zshrc的ZSH_THEME爲文件夾的名稱便可。
使用截圖的主題
剛剛的幾個截圖的主題是我基於robbyrussell修改的,添加了當前登陸用戶的名稱和主機名稱。
可是oh-my-zsh的做者太懶了,我在Github上Fork了項目而後提交我修改後的主題一直也沒有合併,若是喜歡的話能夠直接Clone個人oh-my-zsh分支,而後使用手動安裝的方式安裝oh-my-zsh;
手動安裝完之後能夠把當前的PATH變量設置到~/.zshrc中:
1
2
|
echo
"export PATH=$PATH"
>> ~/.zshrc
source
~/.zshrc
|
修改主題:
修改
ZSH_THEME
爲kafeitu,
本身修改主題
若是提供的主題沒有一個如意的(我就沒有看中一個),你能夠參考別人主題截圖:https://github.com/robbyrussell /oh-my-zsh/wiki/themes 而後看一下對應的~/.oh-my-zsh/themes/foo 的源碼,而後根據本身的須要自定義,最後再修改一下~/.zshrc的ZSH_THEME配置就能夠了。
啓用插件
在~/.oh-my-zsh/plugins/裏面有不少插件能夠選擇啓動,默認已經啓用git插件,若是你像我同樣是一個開發人員(Java),個人插件啓用以下:
1
|
plugins=(ant mvn svn git)
|
Maven插件的截圖

官方插件一覽:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins-Overview
插件安裝方法
參考此處安裝好 zsh 和 oh-my-zsh 後,打開文件~/.zshrc
,其中有以下行:
plugins=(git)
將須要的插件按空格分開,放於此處便可。個人配置以下:
plugins=(git extract z sublime)
修改完後,若是須要在當前shell中生效,須要執行
source ~/.zshrc
git
oh-my-zsh 默認開啓的插件,提供了大量 git 的alias。
詳細列表請參見:
https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git。
extract
功能強大的解壓插件,全部類型的文件解壓一個命令x
全搞定,不再須要去記tar
後面究竟是哪幾個參數了。

強大的目錄自動跳轉命令,會記憶你曾經進入過的目錄,用模糊匹配快速進入你想要的目錄。
sublime
平時使用sublime比較多,該插件可使用命令行打開sublime。
經常使用命令以下:
st
st file_a
st dir_a
stt
各類命令自動補全插件
除上面各類經常使用的插件外,官方還提供了大量插件,大部分是針對某些功能的命令補全,如docker, python, pip, ruby, vagrant等。
雖然 oh-my-zsh 提供了不少插件,不過也不要貪多哦,大量的插件會拖慢打開的速度,所以只安裝你經常使用的就行了。
安裝zsh-syntax-highlighting插件
一樣地,咱們要先下載它的源碼,但在這裏,咱們能夠利用一下oh-my-zsh的插件管理功能:
cd ~/.oh-my-zsh/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
而後,咱們打開~/.zshrc
文件,找到如下段落;
# Which plugins would you like to load? (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)
按照註釋中的提示改爲plugins=(git zsh-syntax-highlighting)
便可。
安裝autojump插件。
一樣地,咱們須要先下載源碼:
git clone git://github.com/joelthelion/autojump.git
而後安裝該程序:
cd autojump
./install.py
最後,咱們只需在~/.zshrc
文件中加入如下代碼便可。
# install autojump
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
安裝Powerline-Shell插件
其過程與autojump的安裝基本相同,先下載源碼:
git clone https://github.com/milkbikis/powerline-shell
再安裝:
cd powerline-shell
./setup.py install
最後再配置~/.zshrc
文件,在其末尾加入以下代碼:
# install powerline-shell
function powerline_precmd() {
PS1="$(powerline-shell --shell zsh $?)"
}
function install_powerline_precmd() {
for s in "${precmd_functions[@]}"; do
if [ "$s" = "powerline_precmd" ]; then
return
fi
done
precmd_functions+=(powerline_precmd)
}
if [ "$TERM" != "linux" ]; then
install_powerline_precmd
fi
而後在cygwin中,咱們就看到以下最終效果:
工欲善其事,必先利其器
,享受zsh帶給你的快捷吧