Fish Shell

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

    image

  • Valid command (blue) vs invalid command (red)

    image

  • Autosuggestions based on history

    image

  • Man page completions

    Example with [command] -[tab]:

    image

    Example with [command][tab]:

    image

  • More

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

image

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 certain configuration tweaks discussed below.

Change default colors

image

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.

image

My prompt function is inside this gist. It may look a bit strange that commands are written in 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.

image

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 some variables using the web interface.

image

View history

image

end

If you found this post useful or have questions, send a tweet or leave a comment. Feel free to show off your prompt, functions or anything fish related in the comments.

Other

Comments