TL;DR

For Beginners: Shell?!

Taken from the Gnome help center:

‘A terminal is a text input point in a computer that is also called the Command Line Interface (CLI).’

So the terminal is what you acutally see, the GUI. You type “cd” in the terminal and hit enter. From there on, the shell gets to work.

‘A shell is a program that provides an interface to invoke or “launch” commands or another program inside a terminal. It also allows you to view and browse the contents of directories. Popular shells include bash, zsh, fish.’

The shell is what translates the commands you entered in the terminal into something your operating system’s kernel can understand and carry out. For example switching directories when entering “cd”.

Some shells you might have heard of are for example bash and zsh. On top of those two technologies, there exist toolings, of which you might have heard, such as oh my zsh.

In the case of fish, a useful tooling is tide.

Switching to Fish

The official documentation got us covered. In the section “Installation” you can find instructions on how to install the fish shell and set it up as default shell. You can also refer to your operating system’s documentation, of which some are listed below:

Installing Tide

If you chose to use Tide, you need to install it. The simplest way is to use Fisher, a plugin manager for the fish shell. In Tide’s README, there is also a section for manual installation.

Fish Shell (& Tide) Setup - Configuration Wizards

Fish shell as well as tide come with graphical configuration wizards. While the fish shell one is web-based, tide comes with a terminal based wizard.

  • start fish configuration wizard: fish_config
  • start tide configuration wizard. tide configure

For a first setup, it is enough to click through and try things out.

My Most Beloved Features

  • command suggestions: as per the official website “fish suggests commands as you type based on history and completions”. During my everday work I tend do use a set of commands in the same order very often. Fish saves me a ton of time because based on what I have used in the past, I do not have to type in lengthy commands all the time. The right command is only a tab key away!
  • beginner friendly setup: Yes, you can have the opinion, that you just “need to deal with it” and learn whatever it takes for your job (or passion) to succeed. I agree to a certain point but no matter if you get started learning/studying informatics, or if you enter the field as a cross-background beginner like I did, there is a lot to of input. You can make your life easier by starting with something easy and working your way from there. The configuration wizards and the extensive documentation make fish shell a very decent shell for me.
  • readable scripts: let me be honest, I did not write a lot of complex zsh or bash scripts in my life so far. Having a cross background coming from biology, I only learned Python and JavaScript at university. Later, I often missed the way Python works out regarding the readability of scripts. In biology, if you can read English, you can read most of the Python scripts required for your daily work. With fish scripts, it is almost the same! I can write if/elses, switch/cases, functions etc. the way I am basically used to. Good bye “if/fi” and “for..do…done”!

Showcase: Completion

Since I have been writing a bit more recently in my blog, this is the suggestion I get when being in my home directory: Screenshot of a terminal with a blue colored prompt and the command “cd” being typed in. A suggestion is shown in light gray saying “projects/hugoBlog/ After switching into the directory if my blog, you might think “maybe it always suggests the “cd” command with the highest count. But it does not. Inside my blog’s directory, “..” for moving one directory up is more likely due to the history of my command usage: Screenshot of a terminal with a blue colored prompt. The current working directory is /home/projects/hugoBlog. A yellow colored part of the prompt holds git information. The command “cd” is typed in a suggestion in gray is shown reading “..”.

Exemplary Function with Completion

A Simple “Say Hello” Function

Script location: /home/youruser/.config/fish/functions

function say_hello --argument language
    switch "$language"
        case en
            echo "Hello World!"
        case es
            echo "¡Hola Mundo!"
        case fr
            echo "Bonjour le monde!"
        case de
            echo "Hallo Welt!"
        case '*'
            echo "Hello World! (Language not supported)"
    end
end

How it works:

  • --argument language: This assigns the positional argument $argv[1] to the more readable variable language.

  • switch "$language": This block checks the value of the language variable.

  • case en, case es, etc.: Each case handles a specific language code and prints the corresponding greeting.

  • case '*': This is a wildcard case that handles any input that doesn’t match the other cases, providing a default message.

Generating a Completion for the “Say Hello” Function

Script location: /home/youruser/.config/fish/completions

complete -c say_hello -f -a 'en es fr de' -d "Language"

How it works:

  • complete -c say_hello: Specifies that this completion script is for the say_hello command.

  • -f : When you create a custom completion for a command, fish often tries to offer filenames as well. -f prevents that, ensuring only your specified arguments are offered.

  • -a 'en es fr de' -d "Language": -a adds the argument and -d provides a description that will appear when you press tab.

Extra Nerd Knowledge

Fish is a project that survived a rewrite succesfully. Read more about the Rust port in their official blog: https://fishshell.com/blog/rustport/