Fish, acronym of friendly interactive shell, is a well equipped, smart and user-friendly shell for Unix-like systems. Fish comes with many significant features, such as auto-suggestions, syntax highlighting, searchable history (like CTRL+r in Bash), smart search functionality, glorious VGA color support, web based configuration, man page completions and more, out of the box. Just install it and start using it in no time. No extra configuration required or you don't have to install any extra add-ons/plug-ins! In this tutorial, let us discuss how to install and use fish shell in Linux.
Table of Contents
Install Fish Shell On Linux
Even though fish is very user-friendly and feature-rich shell, it is not included in the default repositories of most Linux distributions. It is available in the official repositories of only a few Linux distributions such as Arch Linux, Gentoo, NixOS, and Ubuntu etc.
On Arch Linux and its derivatives, run the following command to install it.
$ sudo pacman -S fish
On CentOS 8 run the following as root:
# cd /etc/yum.repos.d/
# wget https://download.opensuse.org/repositories/shells:fish/CentOS_8/shells:fish.repo
# yum install fish
On CentOS 7 run the following as root:
# cd /etc/yum.repos.d/
# wget https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_7/shells:fish:release:2.repo
# yum install fish
On CentOS 6 run the following as root:
# cd /etc/yum.repos.d/
# wget https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_6/shells:fish:release:2.repo
# yum install fish
On Debian 10 run the following:
$ echo 'deb http://download.opensuse.org/repositories/shells:/fish/Debian_10/ /' | sudo tee /etc/apt/sources.list.d/shells:fish.list
$ curl -fsSL https://download.opensuse.org/repositories/shells:fish/Debian_10/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/shells_fish.gpg > /dev/null
$ sudo apt update
$ sudo apt install fish
On Debian 9 run the following as root:
# echo 'deb http://download.opensuse.org/repositories/shells:/fish/Debian_9.0/ /' > /etc/apt/sources.list.d/shells:fish.list # wget -nv https://download.opensuse.org/repositories/shells:fish/Debian_9.0/Release.key -O Release.key # apt-key add - < Release.key # apt-get update # apt-get install fish
On Debian 8 run the following as root:
# echo 'deb http://download.opensuse.org/repositories/shells:/fish/Debian_8.0/ /' > /etc/apt/sources.list.d/shells:fish.list # wget -nv https://download.opensuse.org/repositories/shells:fish/Debian_8.0/Release.key -O Release.key # apt-key add - < Release.key # apt-get update # apt-get install fish
On latest Fedora versions, run:
$ sudo df install fish
You can also install Fish from the openSUSE Build Service.
On Fedora 31 run the following as root:
# dnf config-manager --add-repo https://download.opensuse.org/repositories/shells:fish/Fedora_31/shells:fish.repo
# dnf install fish
On Fedora 30 run the following as root:
# dnf config-manager --add-repo https://download.opensuse.org/repositories/shells:fish/Fedora_30/shells:fish.repo
# dnf install fish
On openSUSE run the following as root:
# zypper install fish
On openSUSE Leap 15.2 run the following as root:
# zypper addrepo https://download.opensuse.org/repositories/shells:fish/openSUSE_Leap_15.2/shells:fish.repo
# zypper refresh
# zypper install fish
On RHEL 7 run the following as root:
# cd /etc/yum.repos.d/ # wget https://download.opensuse.org/repositories/shells:fish/RHEL_7/shells:fish.repo # yum install fish
On RHEL 6 run the following as root:
# cd /etc/yum.repos.d/ # wget https://download.opensuse.org/repositories/shells:fish/RHEL_6/shells:fish.repo # yum install fish
On Ubuntu and its derivatives:
$ sudo apt-get update
$ sudo apt-get install fish
There is also an official PPA available for Ubuntu and its derivatives. Add the PPA and install Fish on Ubuntu as shown below.
$ sudo apt-add-repository ppa:fish-shell/release-3 $ sudo apt-get update $ sudo apt-get install fish
Fish Shell Usage
To switch to fish from your default shell, do:
$ fish Welcome to fish, the friendly interactive shell
You can find the default fish configuration at ~/.config/fish/config.fish (similar to .bashrc). If it doesn't exist, just create it.
Auto suggestions
When I type a command, it automatically suggests a command in a light grey color. So, I had to type a first few letters of a Linux and hit tab key to complete the command.
If there are more possibilities, it will list them. You can select any command from the list by using UP/DOWN arrow keys. After choosing the command you want to run, just hit the right arrow key and press ENTER to run it.
No more CTRL+r! As you already know, we do reverse search by pressing ctrl+r keys to search for commands from history in Bash shell. But, it is not necessary in fish shell! Since it has auto-suggestions capability, just type first few letters of a command, and pick the command from the list that you already executed, from the history. Cool, yeah?
Smart search
We can also do smart search to find a specific command, file or directory. For example, I type the substring of a command, then hit the down arrow key to enter into smart search and again type a letter to pick the required command from the list.
Syntax highlighting
You will notice the syntax highlighting as you type a command. See the difference in below screenshots when I type the same command in Bash and fish shells.
Bash:
Fish:
As you see, "sudo" has been highlighted in fish shell. Also, it will display the invalid commands in red color by default.
Web based configuration
This is yet another cool feature of fish shell. We can can set our colors, change fish prompt, and view functions, variables, history, key bindings all from a web page.
To start the web configuration interface, just type:
fish_config
Man page completions
Bash and other shells supports programmable completions, but only fish generates them automatically by parsing your installed man pages.
To do so, run:
fish_update_completions
Sample output would be:
Parsing man pages and writing completions to /home/sk/.local/share/fish/generated_completions/ 3435 / 3435 : zramctl.8.gz
Disable greetings
By default, fish greets you (Welcome to fish, the friendly interactive shell) at startup. If you don't want this greeting message, you can disable it. To do so, edit fish configuration file:
vi ~/.config/fish/config.fish
Add the following line:
set -g -x fish_greeting ''
Instead of disabling fish greeting, you can also set any custom greeting message.
set -g -x fish_greeting 'Welcome to OSTechNix'
Getting help
This one is another impressive feature that caught my attention. To open fish documentation page in your default web browser from Terminal, just type:
help
The official documentation will be opened in your default browser. Also, you can use man pages to display the help section of any command.
man fish
Set Fish as default shell
Liked it very much? Great! Just set it as default shell. To do so, use chsh command:
chsh -s /usr/bin/fish
Here, /usr/bin/fish is the path to the fish shell. If you don't know the correct path, the following command will help you.
which fish
Log out and log in back to use the new default shell.
Please remember that many shell scripts written for Bash may not fully compatible with fish.
To switch back to Bash, just run:
bash
If you want Bash as your default shell permanently, run:
chsh -s /bin/bash
And, that's all for now folks. At this stage, you might have got a basic idea about fish shell usage. If you're looking for a Bash alternatives, fish might be a good option.
Suggested read:
- Oh My Fish! Make Your Shell Beautiful
- Enable Timestamp For History Command In Fish Shell
- How To Launch Fish Shell In Private Mode In Linux
Resources: