Shirohida

Why I Like the Fish Shell

I’ve tried to use the fish shell and it was unexpectedly fun! First of all, it’s fast! I haven’t realized how slow zsh can be. Fish doesn’t require a complex set up, it works pretty well out of the box. Its tutorial is easy to follow and the documentation is compact and to the point. I am also fond of its design doc. Fish strives to be user-friendly and to have a small set of orthogonal features.

Fish has an unusual configuration wizard: fish_config. It starts a web-server and allows you to choose a theme or set up a prompt with a web-page. Try it out!

Fish config file is located at ~/.config/fish/config.fish.

You don’t have to set up variables in the configuration file, though. Use universal variables instead. For example, this command sets and exports universal variable $EDITOR:

set -xU EDITOR /opt/homebrew/bin/vim

You can append directories to $PATH this way:

set -U fish_user_paths /opt/homebrew/bin $fish_user_paths

This command removes /opt/homebrew/bin from $fish_user_paths:

set -U fish_user_paths (string match -v /opt/homebrew/bin $fish_user_paths)

Universal variables are saved in ~/.config/fish/fish_variables. Don’t edit the file by hand, use set -U instead.

The first thing I’ve tried to do in fish is to re-create my zsh prompt. It was easier than I thought! You can define your own version of the fish_prompt function:

mkdir -p ~/.config/fish/functions
$EDITOR ~/.config/fish/functions/fish_prompt.fish
# ~/.config/fish/functions/fish_prompt.fish
function fish_prompt
    set -l color_username d488f9
    set -l color_hostname cb4b16
    set -l color_cwd 94fd3a

    printf "%s%s%s at %s%s%s in %s%s%s" \
        (set_color $color_username) $USER (set_color normal) \
        (set_color $color_hostname) $hostname (set_color normal) \
        (set_color $color_cwd) (prompt_pwd) (set_color normal)

    __fish_git_prompt " is working on (%s)"

    printf "\n~> "
end

Let’s go through the function body:

  • set -l sets a local variable.
  • set_color returns a special string that colors everything after it with the given color. (set_color normal) resets colors back to default.
  • $USER holds your username.
  • $hostname holds your hostname.
  • prompt_cwd returns your current working directory.
  • It took me a while to find __fish_git_prompt. It prints various information about your git repository. is working on (%s) will be printed only if you are inside a git repo. __fish_git_prompt is documented here.

My version of fish_prompt is a multiline prompt and it looks roughly like this:

claymore at himeji in ~/.config/fish is working on (spacemacs|✚)
~> 

Obligatory link to my fish settings: fish.