Skip to main content
  1. Learn
  2. Software development
  3. Posts
  4. Fish shell: The Command Line companion that’s got us hooked

Fish shell: The Command Line companion that’s got us hooked

PostsSoftware development
Nulab Staff

Nulab Staff

October 13, 2023

If you’re tired of the same old terminal experience, Fish Shell (or just Fish for short) might be the breath of fresh air you need. Let’s dive into what makes Fish Shell a standout choice for your command line needs.

What is Fish Shell?

As the “sh” at the end of its name implies, Fish is a shell. Fish itself stands for Friendly Interactive SHell. Courtesy of Github, this user-friendly command line shell was developed with a special emphasis on user experience.

What sets Fish apart from its competition? For starters, it was developed more recently than its counterparts (with an initial release in 2005), making it a modern and highly functional choice for your command line tasks. It boasts powerful suggestion/auto-completion functionality, friendly syntax highlighting, and its GUI (browser)-based settings/help pages are usable straight out of the box, so to speak.

Install Fish

Installing Fish Shell is a breeze, especially if you’re using Homebrew on a Mac. Just run this command:

1 $ brew install fish

For Linux users, the process is straightforward but a tad different. Be sure to get the official Personal Package Archives (PPA) repository because using a distribution package manager might get you an older version. Here’s how to do it on Ubuntu:

1
2
3
$ sudo aptaddrepository ppa:fishshell/release2
$ sudo aptget update
$ sudo aptget install fish

For other operating systems like Debian, you can find installation instructions on the official Fish website.

Fish functionality

Fish Shell brings a unique flavor to your command line experience with its powerful features. Let’s take a closer look:

Suggestion and completion

One of the standout features of Fish is its suggestion and completion functionality. It’s as easy as hitting the tab key. For instance, try changing directories by typing /usr into the command line.

fish unbuntu cd

Fish suggests /usr/ without even pressing tab. If multiple options share the same starting characters, Fish sorts them alphabetically and suggests the first one. And in cases where there’s no clear suggestion, Fish provides a user-friendly list for you to choose from.

Just type in /s and hit the tab key twice to display an overview of all directories that begin with/s. Use the tab key or arrow keys to move through each.

fish-cd /s

This suggestion functionality isn’t just for paths; it extends to Linux commands and functions too. For instance, typing ssh followed by a space and then tab will give you a list of potential connections registered in known_hosts.

Fish also supports scanning through subdirectories using commands like{directory}/*/.

fish cd3

With these functions, practically anything you’re looking for can be autocompleted using the tab key.

A note: Since the completion of subcommands and options are generated through the man of each application, completion functionality will not be compatible with software installed at any point after Fish is installed. Instead, these updates must be pushed to Fish.

Thankfully, this can be accomplished fairly easily with the following command:

~> fish_update_completions

Syntax highlighting

Fish Shell comes with syntax highlighting out of the box. If you make a typo in a command, Fish will point it out with red letters, like our example below where we mispel “clear” as “clare”

fish typoThis feature also works for directory paths. For example, if you mistype /usr as /user, Fish will promptly highlight the error in red.

fish typo2

Settings and help pages

Fish offers a unique web-based configuration interface that you can access by running fish_config. It allows you to customize various settings, themes, prompts, and more. You can preview different settings, including colors and prompts, before applying them. While it may seem convenient, keep in mind that some color changes, like environment variables and quoted text colors, must still be made manually. In the prompt area, functions need to be created and defined individually. Fish provides an accessible way to configure your shell to your liking.

Package management

Fish has its own package manager, and Fisher is one of the most popular ones. It’s easy to install:

1 curlLo ~/.config/fish/functions/fisher.fishcreatedirs https://git.io/fisher

While Fish itself is feature-rich, you can use packages to enhance it further. Fisher allows you to install themes that are not available by default, adding a personal touch to your shell.

Fish terminal vs. other shells

If you’re already comfortable with Bash, you might hesitate to make the switch to Fish. Here are a few things to consider:

Script Structure

Fish uses a different script structure compared to other shells, making it unique. For instance, Fish does not utilize the && AND operator like Bash does. Instead of apt update && apt upgrade, Fish prefers apt update; and apt upgrade. Similarly, Fish doesn’t use the || operator; you’d use the or command. Conditionals such as if ~ fi also have their own constructions, which you can read more about here.

This unique scripting language might require some adjustment if you’re coming from other shells.

Configuration files: fishrc doesn’t exist

Fish does things differently when it comes to configuration files. Instead of a ~rc file that we’ve all come to know and love, Fish stores its settings in the config.fish file at ~/.config/fish. This means that you can’t apply the same Bash-style syntax directly. Environment variables can be set via the shell, and you can even modify settings via the shell itself. While this might feel different at first, it offers a unique approach to configuring your shell.

One option: Alter the settings via the shell using the export function to instead use the set command to change settings.

From inside config.fish write the following:

1 set PATH /usr/local/bin $PATH

If using the shell, write the following:

1 setU fish_user_paths /usr/local/bin $fish_user_paths

$fish_user_paths is one of Fish’s universal variables and is read before h$PATH.

Fish Shell vs. Zsh

If you’ve heard of Fish Shell, you’ve probably come across Zsh as well. Both shells have their merits, and the choice between them often comes down to your personal preferences. Fish Shell shines with its user-friendly and modern approach, making it an excellent choice for those who prefer a hassle-free experience. Zsh, on the other hand, offers extensive customization and a rich plugin ecosystem, making it a favorite among power users. Ultimately, it’s a matter of what suits your workflow and style.

Bash vs. Fish

Bash, as the default shell on many systems, is deeply ingrained in the world of command line. Its long-standing tradition and wide usage make it a reliable choice. Fish, on the other hand, introduces innovation with its modern features, interactive interface, and enhanced user experience. Fish Shell streamlines your command line tasks with its auto-suggestions and convenient completions. While Bash has its strengths, Fish’s user-friendliness and features set it apart for those looking to embrace a fresh approach.

Diving into Fish Functions

Fish Shell offers a wealth of functions that can enhance your command line experience. From customizing your prompt to defining aliases and creating advanced functions, Fish allows you to tailor your shell to your liking. Functions can automate repetitive tasks, making your workflow more efficient. Learning how to harness Fish functions can take your command line skills to the next level, making your daily tasks more manageable.

Pros and Cons of Fish Shell

Pros:

  • User-friendly and suitable for beginners.
  • Auto-suggestions and efficient completions improve productivity.
  • Syntax highlighting helps catch errors in real-time.
  • A web-based configuration interface simplifies customization.
  • A robust package manager, like Fisher, extends functionality.
  • Offers modern features and a fresh approach to the command line.

Cons:

  • Differences in script structure may require adjustment for seasoned Bash users.
  • Limited support for older systems.
  • Less extensive customization compared to Zsh.
  • Not as widely adopted as Bash or Zsh, which can mean fewer resources and plugins.

Is Fish right for you?

If you prefer using programs as they come, with minimal customization, or you wish for a more robust autocomplete function than what zsh offers, Fish could be an excellent choice. However, for users who enjoy extensive scripting and customization, especially with ~rc files, the differences in script language and file handling might pose some challenges. In the end, it all comes down to your personal preferences.

Fish Shell offers a modern and user-friendly experience, making it a worthy choice for your command line tasks. Whether you’re a beginner or a seasoned developer, Fish Shell’s features and functionality can help you navigate the command line efficiently and effectively. Dive into the sea of Fish Shell and explore a new way to interact with your computer. There may be plenty of fish in the sea, but there aren’t any quite like this one.

Managing your projects with Backlo

Now that you’ve explored the power of Fish Shell for your command line needs, you might be considering how to manage your projects effectively. Backlog, a project and code management tool for development teams, can be your trusted companion in this journey. With Backlog, you can streamline your project management, collaborate with your team, and keep your code organized. It’s the perfect solution to complement your Fish Shell experience and ensure your projects sail smoothly towards success. Dive into the world of Backlog and experience efficient project and code management like never before.

This post was originally published on August 17, 2018, and updated most recently on October 13, 2023.

Related

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life