Fish (**f**riendly **i**nteractive **sh**ell) is the name of an exotic shell. That is a shell with a syntax that is derived from neither the Bourne-Shell nor the C-Shell.
The advantage of fish is that many features that you want in a modern shell come out-of-the-box, so you don't have to install additional software like zsh and oh-my-zsh.
Examples of these features are autosuggestions, 24-bit colors, Man Page Completions (meaning fish automatically parses your man pages and suggests additional options for your commands) or the ability to make options through a web page (when a GUI is installed).
Now, right out of the gate, there's one annoying thing in fish. It's the welcome message. Who needs that, right? When your shell is started, just type:
Can you do that with bash, huh? No, you always have to look it up... It's just that easy!
But there's more. Most fish-specific commands start, you guessed it, with 'fish'. Just type in `fish` and press <kbd>TAB</kbd>. And there you have one of the many cool features of fish: The autocompletion that **just works.**
Now you can navigate with <kbd>TAB</kbd>, <kbd>Shift + TAB</kbd> and your Arrow-Keys <kbd>←</kbd><kbd>↑</kbd><kbd>→</kbd><kbd>↓</kbd>.
To get help, contact your local psychiatrist or type `man`. That will bring up the manual for that command, for example:
If you finally tried fish, you can see something other in fish that's really cool. Everything has cool colors, if you type in something wrong, it is red, without even executing, if you put something in quotes, you see where it ends and why that quote doesn't work, because there's another quotation mark in the quote at position 26.
# a variable set with a space doesn't get sent as two arguments, but as one, as you would expect it.
set turtlefolder 'Turtle Folder'
mkdir $turtlefolder
# This will create one folder, as expected, not two, like in bash...
# Who would even want that? tHiS iS a fEaTurE, nOt a bUg...
# you can even have lists as variables. This actually makes sense, because if you want to have a variable that would create two folders, you just give mkdir a list of your foldernames.
# you can then count the entries in that list with:
count $PATH
# Not only is everything awesome, but in fish, everything is also a list.
# So $PWD for example is a list of length 1.
# To make a list, just give the set command multiple arguments:
# You can also do fancy cartesian products when you combine two list variables:
set a 1 2 3
set 1 a b c
echo $a$1
# Will output : 1a 2a 3a 1b 2b 3b 1c 2c 3c
# Of course, if you separate them, it will see them as two separate arguments and echo them one after the other. THAT is expected behavior @bash.
# There are also other useful things, like command substitutions. For example, when you want to output the returns of two commands in one line. In bash you would do that with
echo "`ls` is in $PWD"
# or
echo "$(ls) is in $PWD"
# if you ask me, that's unnecessary. I always type in the wrong apostrophe. Why not just use two parenthesis, like in fish?
echo (ls) is in $PWD
# Yep, that easy. And thanks to fish's highlighting you can instantly see, if you typed it in correctly.
# And, as you would expect, if you ask me, your commands don't work in quotes. I mean why bash? Ok I'll stop now. But in fish, just do:
echo (ls)" is in $PWD"
# or
set myvar "The file"(ls -a)" is in the directory $PWD"
# will make a List with the string and all files. Try it out. Isn't that cool?
# And to separate these variables in separate arguments, just put a space between them:
set myvar "The files" (ls -a) " are in the directory $PWD"
# functions in fish get their arguments through the $argv variable. The syntax is following:
function print
echo $argv
end
# There are also events, like the "fish_exit"-event (What may that be, hmm?).
# You can use them by adding them to the function definition:
function on_exit --on-event fish_exit
echo fish is now exiting
end
# find events with the command
functions --handlers
# You can use the functions command to learn more about, well, functions.
# For example you can print the source code of every function:
functions cd
functions print
# or get the names of all functions:
functions
# There's while Loops, of course
while test $var = lol
echo lol
end
# for Loops (with wildcards, they are even cooler):
for image in *.jpg
echo $image
end
# there's an equivalent to the range(0, 5) in Python, so you can also do the standard for loops with numbers:
set files (ls)
for number in (seq 10)
echo "$files[$number] is file number $number"
end
# Cool!
# The bashrc equivalent is not fishrc, but the previously mentioned config.fish file in ~/.config/fish/
# To add a function to fish, though, you should create a simple .fish file in that directory. Don't just paste that function in the config.fish. That's ugly.
# If you have more, just add it, but those are the most important basics.