All posts

[Fish] powerful shell with autocompletion, syntax highlight and more

I have been using zsh as my default shell for so long but the other day I was boring and I decided to try new tools for my OS; one of them was Fish Shell.

fish is a smart and user-friendly command line shell for macOS, Linux, and the rest of the family.

I’m very picky with visual styles so I was immediately in love with the syntax highlight feature. It is enabled by default and, as you can see in the GIF, the highlight works as you type, even in the prompt 💯❗️

macOS Installation

You can easily install fish using Homebrew, just execute the following in the terminal:

$ brew install fish

Then, change your default shell with:

$ chsh -s /usr/local/bin/fish

You may want to know what shell do you have in order to revert the changes if you don’t like fish. Execute: echo $SHELL and save the output.

Return to your previous shell

If you were using Bash, then execute:

$ chsh -s /bin/bash

Or if you saved the path of your previous shell using echo $SHELL then, use that path.

Differences between Bash and Fish

Export variables. Use: set -x VARIABLE VALUE

# e.g. Bash
$ export ANSWER="42"
# e.g. Fish Shell
$ set -x ANSWER "42"
$ echo $ANSWER

Command substitution. Use parentheses: (cmd)

$ echo The answer is $ANSWER, (whoami) :)
The answer is 42, gomezhyuuga :)
# Commands are not expaneded inside quotes. However, variables are expanded.
$ echo "The answer is $ANSWER, (whoami) :)"
The answer is 42, (whoami) :)
# Close and reopen quotes instead
$ echo "The answer is $ANSWER, "(whoami)" :)"
The answer is 42, gomezhyuuga :)

$PATH environment variable edition

I would say that modifying the PATH env. variable is a task that many developers have to do quite often. However we can’t do it like we are used to because Fish has a special data structure called lists and $PATH is usually a variable of this type.

In Fish, to append a value to the $PATH variable you must do it like this:

# e.g. set PATH $PATH new_value
$ echo $PATH
/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin

$ set PATH $PATH ~/Development/master/
$ echo $PATH
/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Users/gomezhyuuga/Development/master/

As you can see /Users/gomezhyuuga/Development/master is appended to the end of the list and if you’re clever you will notice that we are just redefining the PATH variable setting as new value to itself, plus a new value appended.

&& combiner. Use: and

In Bash, It’s common to concatenate commands using the double ampersand && to continue executing things if the previous command exited successfully. In fish you should use and instead of the double ampersand.

$ echo "Current exchange:"; and true; and \
     curl ",MXN&base=USD"; and \
     echo -e "\nDone."
Current exchange:
$ echo "Current exchange:"; and false; and \
     curl ",MXN&base=USD"; and \
     echo -e "\nDone."
Current exchange:

(Web) Configuration

Fish Web Configuration

To edit fish’s configuration you can edit the file located at $HOME/.config/fish/ and put any shell code inside it. But what is more exciting is that Fish includes a web configuration ui. To access it you must run:

$ fish_config

It will open a web browser with a location like localhost:8000/* There you can edit many things, among them select the color scheme and even create a custom prompt!


Fish is a great tool as a shell. The feature I love the most is the eager syntax highlighting and also the abbreviations (for which I’ll write about them later). I also find it more easy to customize than Bash or ZSH but it is true that there are just few color schemes for it available online. Nevertheless, I’ve using Fish for a while and it just improved my workflow on the console. It is totally worth a try.