Perfectly Random

machine learning and stuff

Try out the fish shell

Fish is a new shell which makes using the command line much easier. If you’ve already got a very heavily configured traditional shell (like bash) then you probably have replacements for many features of fish. With fish, you get these features out of the box (for the most part).

There are many excellent posts and documentation on the web about installing, setting up and using the fish shell. On this page, my aim is to give you a quick overview of the most important features of fish so that you can make up your mind. I have also provided links to the most useful posts which might save you some time.

Features of fish

  1. fish is not bash

    Before we even begin, let’s note that fish and bash are different, just like csh and bash are different. Many commands and constructs in fish work the same way as bash but there some commands that don’t work the same way. One such example is setting the value of a variable. These are the ways you can add your personal bin folder to path in bash and fish, respectively

    # bash
    export PATH=~/bin:${PATH}
    # fish
    set -g -x PATH ~/bin $PATH

    Fish and bash are different enough that you may not be able to use some bash designed utilities directly. Instead, you would probably need fish-equivalents of those utilites. One such an example is the bashmarks utility which helps you jump between folders in bash. With fish, you can install the fish-equivalent, fishmarks instead.

  2. Colorful, underlined prompt and smarter completions

    The most prominent feature of fish is the colorful, underlined prompt which provides more visual feedback than bash. For example, if a folder is present, you see the entire name of the folder even before you press a Tab key. The already typed letters appear as underlined, cyan colored and the rest of the untyped letters appear in grey.

    Fish helps you find existent folders

    If the letters you’ve typed do not correspond to any matching completion, you see the letters in red. Again, all of this happens before you press the Tab key.

    Fish tells you when there is no matching completion

    You can find more examples here and here.

    Another cool feature is →-key completion in which pressing the → arrow key completes the current completion. This completion is different than bash’s Tab-completion, which does not perform completion when the completion is non-unique. Bash’s Tab-completion instead provides the user with all possible completions. The user, then, has to type enough letters to make the completion unique. Fish’s →-key completion works even when completion is non-unique. I recommend you try it out to see how good it feels.

    Further, fish’s Tab-completion is different than bash’s. Fish’s Tab-completion shows all possible completions like bash, but it goes a step further. Repeatedly pressing the Tab key cycles through all the possible completions, thus eliminating the need to type in more characters.

    Another important completion in fish is the switch-completion, which is absent in bash. Fish’s auto-completion looks through the switches of a command and completes them for you. For example, in bash, typing tree -- and pressing Tab will not yield any results.

     # bash does not provide switch-completion
     tree --

    With fish, switches are completed just like the files and folders without even pressing the Tab key.

    Fish switch completion

  3. Integration with git

    You may already know how to change your bash command prompt to show your git branch and git status. With fish, you can get this functionality and many other features by installing tacklebox.1

    Tacklebox allows you to easily install community-scrutinized themes, plugins and modules which usually work out-of-the-box. I used the urdh theme, which shows git information in the following manner:

    Fish theme showing git information

    Note how the green check mark changes into orange solid dot when the git repository status changes from clean to unstaged.

    See another example here.

  4. fish-config web interface

    This is the most unorthodox feature of the fish shell. You can change colors and prompts, look at your functions and variables and even modify your command history using the web interface. This may not appeal to those who love the command line but it’s very handy should you need it. Type this on the fish prompt


    and it will open up local webpage like this one

    Fish config web interface

    Another example here.

I am sure there are many more features of fish which I have not yet discovered yet.

Installing fish

  1. Make sure you get fish v2.1.0 or later. Fish v2.0.0 does not have the latest Tab-completion tricks that I described.

    For Mac OSX, the post on Hacker Codex is the best page I found for installing and setting up fish.

    For Ubuntu, you can dowload the .deb here and then use the following command

       sudo dpkg -i <fish-deb-file>
  2. The fish official tutorial is a good reference for customizing fish to your taste. The documentation is here.
  3. You probably would want to install Tacklebox which automatically installs Tackle.
  4. Install fishmarks.

Some tips and tricks and snippets

  1. Some plugins of fish may have dependencies that you may need to install. For example, if you find your fish prompt complaining about something called vcprompt, you need to install it.

    Funnily enough, it’s easier to install vcprompt on Mac OSX then on ubuntu.

    # On Mac OSX
    brew install vcprompt

    On Ubuntu, you will need to manually install vcprompt by building it from source. These commands worked for me

    # On ubuntu
    hg clone
    cd vcprompt
    sudo make install

    Same goes for grc. Simiarly, if you have a mercurial repository, you might need to install hg-prompt. These instructions worked for me on both Mac OSX and on Ubuntu.

  2. Set the urdh theme by adding this to your ~/config/fish/ file

     set tacklebox_theme urdh
  3. Some simple snippets to get you started. Put these in your ~/config/fish/ file.
     function reload
         source ~/.config/fish/
     function subl
         open -a "Sublime" $argv
     function ll
         ls -lhG $argv
     function la
         ls -lahG $argv
     function lsd
         ls -d */
  4. Redefining a command. Fish doesn’t have your traditional bash alias command. Instead you need to define a function. The following fish function, however, has infinite recursion which will give you an error
      # Inifinite recursion: this will give you an error
      function ls
           ls -hG $argv

    Instead you can get the alias-like functionality by writing this instead

      # These should work
      function ls
           command ls -hG $argv
      function grep
           command grep --color=auto $argv

Finally, if you know of an excellent use of fish that I’ve missed, please let me know in the comments.

  1. Get it ? Fish, tacklebox … ?