The fish Shell

The fish Shell

By Mark Volkmann, OCI Partner

NOVEMBER 2017

Overview

Nearly all developers spend time using terminal windows, entering commands, such as git, and automating tasks by writing and running scripts. How would you like to use a shell that is more friendly and provides a simpler, more consistent syntax for scripts?

Fish (the friendly interactive shell) is a *nix command-line shell that offers an alternative to shells like bash and zsh.

At a high level, fish provides the following benefits:

  • colorful prompts
  • auto-suggestions while typing
  • auto-completion of commands, their switches (aka options), file paths, variable names, git branches, and more
  • easy access to web-based help
  • error messages that explain the problem and suggest a solution
  • ability to customize colors and the prompt using a web UI
  • highly consistent and simple scripting language where everything is done with commands, not special syntax to be memorized
  • commands never create subshells, so changes they make (such as setting variables) are visible in the invoking shell
  • variables can be set so they are shared with all current and future shells (see "universal variables")

This article explains the fish shell in enough detail for you to determine whether you might prefer it over other shells. Really learning a shell is similar to learning a new programming language. Similar topics are covered here such as variables, functions, string operations, and so on. If writing scripts in other shells has felt tedious in the past, this is your chance to learn a shell that makes scripting easier!

The latest version of fish at the time of this article is 2.6.0. Version 2.7.0 will be released very soon.

License

The fish shell uses the GNU General Public License, version 2. Here's a summary of that license:

You may copy, distribute and modify the software as long as you track changes/dates in source files. Any modifications to or software including (via compiler) GPL-licensed code must also be made available under the GPL along with build and install instructions.

Goals

The goals for fish are listed at https://fishshell.com/docs/current/design.html . Here are the most significant goals:

  • Everything that can be done in other shell languages should be possible to do in fish, though fish may rely on external commands in doing so.
  • Fish should be user friendly, but not at the expense of expressiveness. Most trade-offs between power and ease of use can be avoided with careful design.
  • Whenever possible without breaking the above goals, fish should follow the POSIX syntax.
    (This may lead some to avoid using fish for sysadmin and install types of scripts because there is often a desire for those to be highly portable without requiring installation of new software such as fish. However, for scripts targeted at typical users or scripts that only you will use, implementing them in a shell that is not 100% POSIX compliant is much less of a concern.)
  • The shell language should have a small set of orthogonal features.
  • Everything should be tab-completable, and every tab completion should have a description.
  • Every syntax error and error in a builtin command should result in an error message describing what went wrong and a relevant help page. Whenever possible, errors should be flagged in red by the syntax highlighter.
  • The language should be uniform so that once the user understands the command/argument syntax, they will know the whole language and be able to use tab-completion to discover new features.

History

The first release of fish was on February 13, 2005. Axel Liljencrantz was the main developer and maintainer of versions 1.0 to 1.23.1 which were in SourceForge. The last 1.x release was in March 2009. Various people maintained forks at Gitorious and elsewhere, but it seems no releases were ever made. A person that goes by "ridiculousfish" got involved in late 2011 and released a beta of a fork called "fishfish" in 2012. This incorporated much of the work of previous fish contributors and eventually became fish 2.0 which was released on September 1, 2013.

fish was originally implemented in C but is now primarily C++.

fish 3.0 is targeted to be released in Q1 2018. For a list of fixes/features targeted for this release, see https://github.com/fish-shell/fish-shell/milestone/18. For a list of additional fixes/features that *may* be in this release, see https://github.com/fish-shell/fish-shell/milestone/7.

Sections

The remainder of this article is split into four sections.

  1. The first section describes using fish. Some readers may wish to stop there and just reap the benefits of fish in its default configuration.
  2. The second section describes customizing fish. This targets readers who want to go beyond the defaults.
  3. The third section describes scripting in fish. Readers who wish to automate repetitive tasks will benefit from learning this material.
  4. The fourth section provides additional information that doesn't fit into the previous sections.

 

Please continue reading the article on Mark Volkmann's GitHub Pages site.

Software Engineering Tech Trends (SETT) is a regular publication featuring emerging trends in software engineering.