Fish Shell Cheat Sheet

About Fish

Fish is a shell for various *NIX environments, humorously marketed as "a shell for the 90s".

Why Would You Want to Use Fish?

The downside of Fish is that it discards most backwards-compatibility with traditional shells (ash, bash, zsh, etc.)

That downside is also the upside, however, Fish features a modern syntax designed from scratch, rather than being an extension of a 40 year-old design

What does that mean? You may not be able to copy+paste CLI commands off the web anymore (at least not without prepending e.g. bash -c "$ARG" ). On the other hand, it's way easier to create your own functions, loop through lists, etc. You also get some pretty advanced auto-suggestions which are useful.

This Tutorial

So far this is pretty limited, more than anything I wanted to make it for my own purposes because I keep having to look up the same stuff. Their site has a ton of documentation on the properties of Fish, but I feel could have more content on the practical application

Topics

Exporting Variables

Fish itself doesn't rely on exports, but other programs do, so it's important to know how to do it. Easy examples of variables you may want to export are EDITOR and PYTHONPATH. Doing so is quite simple:

>set --export --universal --append PYTHONPATH "$HOME/.local/bin/"

Here the --export flag causes the variable to become available system-wide

Setting $PATH

Regardless of the shell you're using, one of the most important variables to have set is always "PATH", which tells the computer where to look for binaries to execute. If not set correctly, you can end up with programs that are installed, but not runnable.

Prominent examples of why you'd want to alter your PATH would be to allow your system to execute programs installed by package managers operating at the user-level like Python's pip and Node's npm

Anyways - how to set PATH easily was a bit controversial at first in Fish, but ultimately they came up with what I feel is a great solution, you don't need to directly set it at all. PATH exists globally (rather than universally) to allow different fish instances to be configured differently, but we don't want to set $PATH each time we open a new shell. Doing so by hand would be extraneous, and doing so using a config file will probably lead to your PATH variable having lots of repeats

So the system they implemented is quite a nice one, you simply set the variable once:

>set --append --universal fish_user_paths {new_path}

using the --append option ensures that in case you already have a user path set, we're adding to it rather than replacing it using the --universal option makes it so that all instances of the shell have access to it, every new shell you open will have the correct PATH now.

Creating Aliases

The fish shell has an "alias" command, but it's actually a wrapper around the function command. To create a new alias, (using apt as an example) simply:

>alias update "sudo apt-get update & sudo apt-get upgrade -y"

Now to make it permanent, instead of having to write it to a config file we can just do:

>funcsave update

And it will be saved forever and available in all our fish instances.

Getting More Plugins

Currently, I manage my plugins with fisher, it is compatible with oh-my-fish as well. A starting place for finding packages is the awesome-fish curated collection of packages.

Conclusion

I'm hoping to add more content later. As always, I made this tutorial purely for the benefit of myself and any potential readers, however, if you'd like to buy me a cup of coffee, you may send a donation through PayPal.

License



This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.