Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
93 lines (64 sloc) 3.27 KB

Zsh / Oh-My-Zsh + iTerm2 + Powerline

Fish Shell + iTerm2 + Powerline 一文中我曾介紹過如何使用 Fish ShellPowerline 來取代 macOS 中內建的 Terminal 終端機與 Bash shell。雖然 Fish 預設的設定對一般使用者來說已經非常友善了,但隨著使用時間越來越長,我發現 Fish 對於 Bash 的相容性其實仍然相當不足。因此,在這篇筆記中,我將記錄如何使用 Zsh 以及 Oh-My-Zsh 來取代 Bash ,並透過 zsh-autosuggestionszsh-syntax-highlighting 這兩個 plugins 來保有 Fish 的強大自動補齊及語法提示功能。同樣的,這篇開發環境配置筆記仍然會使用到 Xcode IDE 的開發環境,並需要安裝 Homebrew 套件管理工具以及 iTerm2 終端機,若還沒安裝請點擊連結安裝。


Open iTerm2, and run the following commands to install Zsh and Oh-My-Zsh:

$ brew install zsh
$ chsh -s /bin/zsh
$ git clone git:// ~/.oh-my-zsh

Copy Oh-My-Zsh's zshrc.zshrc-template as .zshrc. If you have your own .zshrc file, feel free to use your's:

$ cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Install plugins via Homebrew:

$ brew install zsh-autosuggestions
$ brew install zsh-syntax-highlighting

Enable plugins by adding the following lines to your .zshrc file:

source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

Now install Powerline:

$ brew install python
$ pip install powerline-status --user
$ pip install powerline-shell

Define your zsh prompt by adding the following codes to your .zshrc file:

function powerline_precmd() {
   PS1="$(powerline-shell --shell zsh $?)"

function install_powerline_precmd() {
  for s in "${precmd_functions[@]}"; do
   if [ "$s" = "powerline_precmd" ]; then

if [ "$TERM" != "linux" ]; then

Install the Powerline Fonts by typing the commands below:

$ git clone
$ ./fonts/

Finally, go to iTerm2 Preferences and click the Text tab.

iTerm2 Fonts 01

Choose any font style including for Powerline

iTerm2 Fonts 02

You are all set!




  1. The following command allows you to change shell back to the Bash just in case:

    $ chsh -s /bin/bash
  2. You can store your .zshrc file somewhere like GitHub or GitHub Gist, so that you won't need to configure your shell setting every time.