The Fish shell simplifies the console

Easy as Fishing


The Fish shell offers some user-friendly features for command line beginners.

By Andreas Kneib

Gary Yu, Fotolia

Most Linux newcomers (and even some Linux veterans) shudder at the thought of using the command line. Consulting the manuals for the major command line interpreters is more likely to confuse a newcomer than to help. The manpage that comes with the Bash shell has around 4000 lines, and the Zsh manual has almost 17,000.

The reason for this complexity is that these command line interpreters were not really designed with the beginning user in mind; instead, command line interpreters were created for efficiency and to facilitate streamlining and automation by skilled users.

Axel Liljencrantz launched the Fish shell in February 2005 as a friendlier shell alternative. Fish stands for "Friendly Interactive Shell." The Fish shell has a number of features that make life easier on users and improve the appearance of the command line. For example, Fish supports tab completion, syntax highlighting, and a browser-based help system.

Fish will even auto-complete the options for common utilities such as make, ls, du, or programs such as Mplayer. (Users with Zsh will be familiar with the Fish shell's auto-completion feature.)

You can download the shell from the project homepage at [1]. The download section has a collection of packages for various distributions, from Debian, through Gentoo and Suse, to Fedora Core. If you prefer to build the Fish shell from the source code, just download the tarballs from the same site.

First Aid

After completing the installation, launch Fish in your standard shell by giving the fish command. A Welcome to fish message appears, pointing out the external help option: Type help for instructions on how to use fish.

The help option launches your default web browser with the help pages, which will be located at a location such as /usr/share/doc/fish/ (depending on your distribution). Fish will either evaluate the $BROWSER environmental variable to identify your browser, or, if this variable is not set, just scout around for a suitable program.

The Fish shell is capable of running help automatically in Firefox in an X window environment. Fish will revert to a text-based browser in a command line-only environment. You can pass in a number of parameters to the help command: help help lists the help on help, for example.

More Help

The software has an internal sanity test that will pick up on input errors. For example, if you enter dog=cat at the command line to define a variable, the Fish shell will automatically respond with a comprehensive explanation, a suggestion, and an offer to take you to the help page.

Of course, you might ask what sense it makes to export help to HTML, rather than keeping it in manpages and info pages. For users with low-powered computers, who might not appreciate browser windows popping up whenever they have a question, Fish also provides a manpage alternative, although the manpages included with Fish are fairly terse in comparison with the HTML help.

Syntax Highlighting

Fish's syntax highlighting feature really catches your attention right from the first command. The Friendly Interactive Shell colors your entries red, until it finds an unambiguous command. If you press tab while you are in a red display area, Fish will show you any patterns that match the characters you have entered, and it will tell you if these patterns are links, programs, or directories.

In some cases, Fish even tells you something about what the tools do (Figure 1). If the output for a command is more than a terminal window can hold, Fish will open up a pager, which you can scroll through by pressing the arrow keys.

Figure 1: Fish provides a summary of commands matching the input text.

The command line follows a similar approach with the options for some commands. Again, shell commands are displayed in red, until they become unambiguous, and again, tab completion is available. The scripts below /usr/share/fish/ take care of this.

If you type help completion, the guide will tell you how to extend this feature. Fish's ability to point out different kinds of parentheses, braces, and so on in the command line is another good idea that helps you keep track of longer commands.

Automatic Launch

The open command promises to be a big help on launching programs. You can use this command to avoid needing to type a program name. For example, open test.pdf will load the test.pdf file in a PDF viewer, thus supporting wildcards such as the asterisk *. The following command opens HTML documents in the current directory in a web browser:

akneib@comone ~> open *.html

The settings in your Mimetype database specify which program will open .html files. Fish bases its launch decisions on the Mimetype database, and it maps files to applications as specified in the .desktop files that are also used by KDE and Gnome. Although this technique succeeds in associating files with programs, shells such as Zsh have a more elegant solution to the problem of file associations. The command alias -s html=firefox lets you associate web pages with Firefox without involving KDE, Gnome, or the Mimetype database.

Conclusions

For a program at this early stage of development, The Fish shel has some very useful mechanisms, such as syntax highlighting and completion. The help function included with Fish is well-designed. Power users might not like the desktop orientation of the program, but the Fish shell certainly helps remove any inhibitions that beginning Liux users might have about working from the command line.

INFO
[1] Fish website: http://roo.no-ip.org/fish/