DEV Community

Cover image for Why I use Fish Shell over Bash and Zsh ๐ŸŸ
Alec Brunelle
Alec Brunelle

Posted on • Edited on • Originally published at Medium

Why I use Fish Shell over Bash and Zsh ๐ŸŸ

Want more great content like this? Sign up for my newsletter, visit: alec.coffee/signup

One of the main allurements of Apple is that things "just work". Most of the people who use their products are covered with the features they release and Apple spends little time on anything else. The features they do ship, are polished, have sensible defaults, and are intentional. This is what I believe the Fish shell has become. No wasted time scouring the web for config files others have shared, the best plugins to use, or how to get integrations working with your particular setup.

This shell is meant for most people, Fish stands for Friendly Interactive Shell, that's why I can recommend it to anyone I work with. They have a very detailed design document. It's not meant for the likes of system admins who are constantly logging into multiple servers a day. It will never be the default installed shell on most operating systems.

Once you install it, brew install fish, you are off to the races. You have a shell where you can become super productive and your favourite tools work as intended. It doesn't try to be the best at everything, but nails the essential core features which make the user experience extremely enjoyable.

TLDR

  • Syntax highlighting
  • Inline auto-suggestions based on history
  • Tab completion using man page data
  • Intuitive wildcard support
  • Web based configuration

Let's break it down

Syntax highlighting

My worst memories of bash come from the absence of this feature, syntax highlighting. A simple thing which makes you think, "wow, now I am using a shell from the 90's"! You can notice it working in the below gif when I try to go to folder_that_doesnt_exist, the text turns red. The text then turns blue when it's a valid command.

Inline auto-suggestions based on history

Smart auto-suggestions are seldom seen, let alone built-in. Instead of just beating the competition, the Fish team thought to demolish it. Using the history of your commands, it suggests commands which you can complete with the right-arrow key. You can also, as I do this gif, auto-complete one word or folder at a time with option + right-arrow key.

Fun fact, if search results are huge, Fish shell will paginate!

Tab completion using man page data

This is because Fish knows how to parse CLI tool man pages in many different formats. Git, Docker CLI, package.json, you name it, most commands you try, it will have auto-completions for it.

You can use tab to get all the options.

All npm scripts for this package, with values of what they actually run, IN THE TERMINAL WUT
example-of-fish-shell-tab-complete

Intuitive wildcard support

In bash, I never liked having to use different flags for selecting files or contents of a folder.

Regularly, this would be done with:



rm -r folder_1


Enter fullscreen mode Exit fullscreen mode

I have always been a fan of familiarity, and wildcards are just that. You can use them in any command filter down the exact files you need with ease.

e.g.



ls *.jpg


Enter fullscreen mode Exit fullscreen mode
How I feel while using Fish

Web based configuration

Type in:



web_config


Enter fullscreen mode Exit fullscreen mode

and you get an entire website dedicated to messing around with any config you do need to touch.

A tiny customization needed to go the extra mile

There aren't a lot of extra packages needed for Fish. Personally, I only use 2, which is wild because at one point I know my Oh-My-Zsh plugins were past 10.

Oh My Fish

A homage to the great Oh My Zsh, omf is the most popular package manager for Fish. I use this to install just two packages, one for nvm and one for spacefish.

SpaceFish

Special mention to Spacefish for being the best shell prompt I have ever used. Support for showing:

  • Current Git branch and rich repo status
  • Current Node.js version, through nvm
  • Package version, if there is a package in the current directory (package.json for example)
Spacefish example
spacefish-shell-prompt-example

Config file

You also have access to a config file at .config/fish/config.sh. This is where you can set aliases up or set some extra path extensions.

Caveats

Not being POSIX compliant can scare some developers away. But really in my three years of usage (mostly Node.js, javascript, ruby, e.t.c.), I have not encountered any issues. Some commands I get from the internet which are Bash specific, I'll just exit and then come back to Fish when I finish. This Stackoverflow post goes into it more if you are so inclined.

But it's easy to be compatible...

Say you have a bash script to run, with Fish you still can:



bash script.sh


Enter fullscreen mode Exit fullscreen mode

Another tip is that you can put this at the top of the file:



#!/usr/bin/env bash


Enter fullscreen mode Exit fullscreen mode

and then make sure its an executable:



chmod +x script.sh


Enter fullscreen mode Exit fullscreen mode

and voila, you can run it as a regular script:



./script.sh

Enter fullscreen mode Exit fullscreen mode




Resources:

Like this post? Consider buying me a coffee to support me writing more.

Want to receive quarterly emails with new posts? Signup for my newsletter

Top comments (4)

Collapse
 
nanohard profile image
William Antonelli

Instead of exiting, I use
bash -c 'command'
This is useful for scripts or programs as well where you need to be bash-compliant.

Collapse
 
johnny4fun profile image
Johnny Zhang

The same! But I still hope that Fish could be compatible with bash/sh

Collapse
 
aleccool213 profile image
Alec Brunelle

This is a great addition! Thanks!

Collapse
 
kevomac12 profile image
Kevin Wilson

Hey, how familiar are with fish? Have you modified the 'Default login' or the 'Startup directory text boxes on the shell tab?

Need a hand