Skip to content
cnandreu
2 min read

Fish Shell

Why I switched from bash to fish, plus how to install it, make it your default shell, and customize it with fish_config.

Fish advertises itself as a smart and user-friendly command line shell for OS X, Linux, and the rest of the family. If you’re using bash, I highly recommend reading this post and trying fish.

Features

  • Colors out of the box
  • Syntax highlighting as you type — valid commands show up blue, invalid commands red
  • Autosuggestions based on your history
  • Man page completions — hit tab after a command (or a partial flag like [command] -[tab]) and fish suggests options straight from the man pages, with descriptions
  • More in the official tutorial

Install

Visit their website at fishshell.com and look under Go Fish. Since I already had Homebrew, I simply ran the following command:

brew install fish

Setup

  • Open Terminal.app
  • Preferences (Command + ,)
  • Startup tab
  • Find the text label Shells open with:
  • Click on Command
  • Paste /usr/local/bin/fish

Alternatively you can change it via the command line:

chsh -s /usr/local/bin/fish

Make sure the file path matches the location of the fish executable on your machine.

fish_config

Fish provides a web interface that enables some extra configuration. Simply type fish_config inside your shell and hit enter.

A browser should open (localhost:8000) with a website that allows you to perform the configuration tweaks discussed below.

Change default colors

The web interface includes a color picker with a handful of pre-made color schemes you can apply to your shell with a click.

Change the prompt

The prompt function is defined here: ~/.config/fish/functions/fish_prompt.fish. There are various pre-defined prompt functions you can pick from, or you can create your own.

My prompt function is inside this gist. It may look a bit strange that commands are written on a second line. However, since my terminal usually takes up more space vertically than horizontally, I prefer it. There’s also a blank line between each command to help improve readability. If you’re inside a git repository folder it should also display the name of the branch you’re on.

Add functions

Functions in fish wrap common shell tasks. For example, I created a new file, ~/.config/fish/functions/gs.fish, with the following:

function gs --description 'alias for git status'
    git status -s $argv
end

Now every time I type gs into the terminal it will run git status -s.

The example above is just a simple alias, but hopefully it illustrates how easy and useful it can be to create functions.

View variables

It’s possible to set environment variables using the following syntax: set -x greeting hello. You can view your variables using the web interface.

View history

The web interface also lets you browse and search your command history.