From Bash to Zsh to Fish!

First of all. This is related to me, not anyone else. You might not like it, you could even hate it. I could also have some wrong information (feel free to correct me if I do). If that is fine with you, continue reading.

If you don’t even know what a shell is. Simply put, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform.

When you open your command line (terminal) you run a shell, a program. By default you probably have Bash (Bourne Again Shell).

Then you can install another shell, I installed one called Zsh. Because I’m lazy I’ll copy Wikipedia (feel free to skip it, its boring);

Zsh is an extended Bourne shell with a large number of improvements, including some features of bash, ksh, and tcsh.

Features include:

  • Programmable command-line completion that can help the user type both options and arguments for most used commands, with out-of-the-box support for several hundred commands
  • Sharing of command history among all running shells
  • Extended file globbing allows file specification without needing to run an external program such as find
  • Improved variable/array handling
  • Editing of multi-line commands in a single buffer
  • Spelling correction
  • Various compatibility modes, e.g. zsh can pretend to be a Bourne shell when run as /bin/sh
  • Theme-able prompts, including the ability to put prompt information on the right side of the screen and have it auto-hide when typing a long command
  • Loadable modules, providing among other things: full TCP and Unix domain socket controls, an FTP client, and extended math functions.
  • The built-in where command. Works like the which command but shows all locations of the target command in the directories specified in $PATH rather than only the one that will be used.
  • Named directories. This allows the user to set up shortcuts such as ~mydir, which then behave the way ~ and ~user do.

Stop skipping here!

I used It for a long time but lately I came across Fish! Another shell, and has a weird name I know. It stand for Friendly Interactive SHell, and boy I fell in love ❤!

I’ll be robotic here. The Fish shell attempts to be more interactive and user-friendly than former shells. The goal is to give the user a rich set of powerful features.


That was longer that I expected, right. So, Features! (Read the headlines for saving some time)

Autocomplete and Autosuggestion

One of the things I liked about Fish, or the best things I liked about it is the autocomplete and suggestions are inline and works for almost anything and its based on history and what not. so for example, it works with switches like ls --he and it gives you ls --help. It also great that all of this happens like in real-time. So you’re typing a command, the command color is red, the suggested completion is in muted-grey, and once you type the correct command then it will turn into white, or blue, depends on you.

Interactivity, huh!

it really saves time and it start as soon as you type the first letter. Left arrow to auto-suggestions and tab for auto-complete. worth mentioning, Alt+Left arrow to just take the first part of the suggestion and you can hit it until you get there ;)

The grey is the suggestion, `s` is not recognized as a command so its red.

Pressing the Tab key will list all known parameters, and what they do. This is done by fish going through the “Man Pages” of that particular program.

Syntax Highlighting and Beautiful Colors

I know that this can be done in other shells, but it requires you to do so. Fish has this by default.

Web Interface

Another noticeable feature of fish is that it can be configured through a web interface, running on a local web server. This is as far as i know the only shell that has this. It really saves times ;o

Flow Control

Fish shell replaces the logical operators used by bash like “||”, “&&”, and “!”, and replaces them with “and”, “or”, and “not”. This makes it way more readable.

Error Messages

Not much, but, it worth mentioning. Error messages are more obvious and easy to understand.

Enhanced Scripting

Scripting with Fish is pretty great compared to bash. Its syntax is simple, clean, and consistent. Pretty much look like python.

A peak into the difference;

# bash
export PATH=~/bin:${PATH}
# fish
set -gx PATH ~/bin $PATH

Installing

  • Arch: pacman install fish
  • macOS: brew install fish
  • Ubuntu: for some reason, you always have to add a damn repository before you could install anything!
sudo apt-add-repository ppa:fish-shell/release-2
sudo apt-get update
sudo apt-get install fish

To make it fish your default shell:

which fish to check where fish is (sometimes its different)

[Almoullim] > which 
/usr/bin/fish
[Almoullim] > chsh -s /usr/bin/fish

Basic configuration

Create the Fish config directory:

mkdir -p ~/.config/fish

Create initial config file:

vim ~/.config/fish/config.fish

Initial config file contents, which adds /usr/local/bin to the PATHenvironment variable:

set -g -x PATH /usr/local/bin $PATH

Open a new terminal session, it should now load with the Fish shell by default. You can enter help and hit enter, this open the user documentation in your default browser.

To open the web configurating you can isse this command:

fish_config

… and then visit http://localhost:8000/ in your browser.

Fish can parse your installed man pages and automatically generate completion files for your command-line tools. You should periodically run the following command to update those completions, which are stored in ~/.config/fish/completions by default:

fish_update_completions

Now what?

These will help you setup themes and plugins.

Install omf (Oh-My-Fish): github/oh-my-fish

Oh My Fish provides core infrastructure to allow you to install packages which extend or modify the look of your shell. It’s fast, extensible and easy to use.

curl -L http://get.oh-my.fish | fish

Install Tacklebox: github.com/tacklebox

Tacklebox is a framework for the Fish shell that makes it easy to organize and share collections of useful shell functions, tools, and themes.

curl -O https://raw.githubusercontent.com/justinmayer/tacklebox/master/tools/install.fish
cat install.fish | fish; rm install.fish

THE END!