The Fish shell, or “Friendly Interactive SHell,” is a user-friendly command line interface for Linux and other Unix-like systems. Known for its autosuggestions, theming, and scripting capabilities, Fish enhances your command line experience with features suitable for both beginners and experienced users.

Getting Started with Fish

First things first, if you’re new to Fish, you might want to configure it to suit your preferences. Fish provides a handy web-based configuration interface:

fish_config

This command opens a browser window where you can tweak your Fish shell settings visually.

Autosuggestions

One of the standout features of Fish is its autosuggestion capability. As you type commands, Fish suggests possible completions based on your command history and a predefined list of commands. Here’s how you can interact with autosuggestions:

  • Press or Ctrl+F to accept the suggestion.
  • Press Alt+→ to accept just one word of the suggestion.

Working with Variables

Fish allows you to work with variables in a straightforward manner. You can set temporary variables like this:

set name "Mister Noodle"

Note that if you omit the quotes, Fish will interpret it as a list of two arguments. To delete a variable, use:

set -e name

For universal variables that persist across sessions, use:

set -U name "Mister Noodle"

Using Wildcards

Wildcards in Fish make it easy to work with files and directories. For example, to list all files with an extension:

ls *.*

For recursive directory searches, use the double asterisk:

ls /var/**.log

Conditionals

Fish supports conditional statements, making it easy to write scripts that make decisions:

if grep fish /etc/shells
    echo Found fish
else if grep bash /etc/shells
    echo Found bash
else
    echo Got nothing
end

Functions

Functions in Fish are powerful and can accept arguments using the $argv list. Note that array indices start at 1, not 0. Here’s how you can create, save, and delete functions:

funced name
funsave name
functions -e name

Aliases and Abbreviations

Aliases and abbreviations can save you time by shortening commonly used commands. To create an alias:

alias -s gco="git checkout"

For abbreviations, use:

abbr -a gco "git checkout"

This appends the abbreviation of gco to git checkout. You can save your abbreviations to a file:

abbr > ~/.config/fish/conf.d/myabbrs.fish

Sequences

Fish provides a seq command to generate sequences of numbers:

seq LAST
seq FIRST LAST
seq FIRST INCREMENT LAST

You can use this to create multiple files at the same time, for example the following code create the files t8, t5, and t2:

touch t(seq 8 -3 2)

Paging and Navigation

When it comes to paging through command output, Fish offers intuitive controls:

  • Use the up and down arrows to navigate line by line.
  • Press Ctrl+R to page forward and Ctrl+S to page backward.

Navigating directories in Fish is straightforward. Use cd to change directories and pwd to print the current directory. Fish also allows you to navigate your directory history:

  • Use Alt+Left to go back.
  • Use Alt+Right to go forward.

For printing and navigating directory history, use:

dirh
cdh