Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time

Fish Shell + iTerm2 + Powerline

在編寫程式及進行系統操作時,我們常常大量地使用 Terminal 終端機與 macOS 預設的 Bash shell。然而,系統預設的 Terminal 與 Bash 看久了實在不是很舒服也相當不方便,因此,這篇開發環境設置筆記將會介紹如何安裝 Fish ShellPowerline 這個 plugin 在 iTerm2 終端機上。這篇開發環境配置筆記會使用到 Xcode IDE 的開發環境,並需要安裝 Homebrew 套件管理工具以及 iTerm2 終端機,若還沒安裝請點擊連結安裝。

Note

Open iTerm2, and run the following commands to install Fish:

$ brew install fish
$ echo "/usr/local/bin/fish" | sudo tee -a /etc/shells
$ chsh -s /usr/local/bin/fish

Now install Powerline:

$ brew install python
$ pip install powerline-status --user
$ pip install git+git://github.com/powerline/powerline
$ git clone https://github.com/milkbikis/powerline-shell
$ cd powerline-shell
$ cp config.py.dist config.py
$ ./install.py

Now, edit ~/.config/fish/config.fish by typing and redefine fish_prompt as follow:

function fish_prompt
   ~/powerline-shell/powerline-shell.py $status --shell bare ^/dev/null
end

Install the Powerline Fonts by typing the commands below:

$ git clone https://github.com/powerline/fonts.git
$ cd fonts
$ ./install.sh

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!

Screenshot

fish-shell-iterm2-powerline

[Optional]

  1. In Fish, the export command is not allowed to used to edit our variables, like $PATH. If you want to append a new path to your $PATH variable, here is a simple way by using set command like the example below:

    $ set PATH $PATH <new_path>
    
  2. The following command allows you to change shell back to the Bash just in case:

    $ chsh -s /bin/bash
    
  3. Since Fish doesn't have good compatibility with Bash, I recommend using Zsh + Oh-My-Zsh as a better option. To do so, see more details here.