eliseomartelli
HomeBlogPhotosAbout

Fish on macOS - A week long experiment

Dec 16, 2024 - ⏱️ 2 minutes to read

For the next week, I intend to experiment with utilizing Fish as my primary shell on macOS. This challenge was initiated this morning by Francesco, who encouraged me to explore Fish as an alternative shell.

Switching to Fish for a week?

Installation

I followed these steps to install Fish:

  1. I used Homebrew to install fish.
$ brew install fish
  1. I then added fish to the list of available shells.
$ which fish | sudo tee -a /etc/shells > /dev/null
  1. Then I switched my default shell.
chsh -s $(which fish)

Something cool

A positive aspect of Fish is the use of the conf.d directory, which helps organize configuration files into individual scripts, making it easier to manage and update customizations without cluttering a single configuration file.

One thing I’ve noticed is that Fish feels noticeably faster than my previous setup with Zsh + Oh My Zsh. It seems more responsive, and the startup time feels snappier.

A first challenge

The default keybinding to edit a command using $EDITOR is Meta+E (contrary to other shells ⌃+X ⌃+E). Since I use the ⌥ (Option) key as a compose key for typing special characters, I cannot remap it to the Meta key. 
I had to configure a custom bind to bring back ⌃+X ⌃+E functionality.

~/.config/fish/conf.d/bindings.fish
# Edit command
bind \cx\ce edit_command_buffer

Dotfiles

If you want to take a look at my configurations or follow along with the changes I make throughout this experiment, you can check out my dotfiles here.

Throughout the week, I will continue experimenting with Fish and refining my setup. Expect further updates!


Day 2

Fish is not POSIX-compliant, but that’s intentional. It’s designed as a user-friendly interactive shell, not as a scripting shell.

Scripts and Compatibility

Many scripts use the following shebangs:


random_script.sh
#!/bin/bash

or

random_script.sh
#!/bin/sh

or
 (even better)

random_script.sh
#!/usr/bin/env bash

Indeed, these scripts presume POSIX compliance, which Fish does not natively support. However, they also specify the interpreter to be used for executing those scripts. As noted in the Gentoo Wiki:

fish should not be set as the system shell by making it the target of the /bin/sh symlink; this could result in an inoperable system.

Key Point: Utilize Fish interactively, while maintaining Bash or a POSIX-compliant shell as the system’s default shell.


Counterpoint

#include <stdlib.h>
 
int main() {
  const char *command = "echo $SHELL";
  exit(system(command));
}

The system() function executes the provided command (in this instance, echo $SHELL) within a new shell, your default interactive shell (in my case, fish). But you shouldn’t really use system()...

Subscribe to RSS

Writing

Here are some of my thoughts.

Newsletter

Stay in the loop and get news about what I have my eyes on!

Past Issues