Operations 12 min read

Unlock the Power of Fish Shell: Install, Switch, and Customize Like a Pro

This guide walks you through installing Fish Shell on macOS, switching from Bash or Zsh, exploring its standout features such as syntax highlighting, autosuggestions, tab completion, web‑based configuration, and shows how to customize prompts and greetings with practical code examples.

Efficient Ops
Efficient Ops
Efficient Ops
Unlock the Power of Fish Shell: Install, Switch, and Customize Like a Pro

Introduction

Fish Shell is a modern command‑line interface praised for its built‑in features, syntax highlighting, smart suggestions, and web‑based configuration, making it popular among developers and system administrators.

1. Installation

On macOS, install Fish via Homebrew:

<code>brew install fish</code>
Note the installation path shown in the screenshot; you may need it later.

2. Switching Shells

2.1 Manual Switch

Start Fish temporarily:

<code>fish</code>

Exit back to the previous shell with:

<code>exit</code>

2.2 Set as Default Shell

Add Fish to

/etc/shells

and change the default with

chsh

:

<code>sudo vim /etc/shells</code>

Then run:

<code>chsh -s /opt/homebrew/Cellar/fish/3.6.1/bin/fish</code>

To revert, use

chsh -s /bin/zsh

or

chsh -s /bin/bash

.

Because Fish syntax differs significantly from Bash, it is recommended to use it manually rather than as the default shell.

3. Handy Features

3.1 Syntax Highlighting

Valid commands appear blue, invalid commands red, valid paths are underlined, and mismatched brackets or commas are highlighted.

3.2 Autosuggestions

Fish suggests completions in a faint gray; accept with

-&gt;

or partially with

Alt + -&gt;

.

3.3 Tab Completion

Press

Tab

after typing a few characters to see possible commands, arguments, or options.

3.4 Web‑Based Configurator

Run

fish_config

to open a browser UI for themes, prompts, functions, variables, history, and key bindings.

<code>fish</code>
<code>fish_config</code>

3.5 Custom Configuration File

Edit

~/.config/fish/config.fish

to add aliases, functions, or other settings. Example aliases for Git:

<code>alias g "git"
alias gst "git status"
alias grs "git reset --soft"
alias grh "git reset --hard"
alias gb "git branch"
alias gba "git branch -a"
alias gl "git pull"
</code>

3.6 Easy‑to‑Read Syntax

Fish uses a high‑level syntax. Examples include

if

,

switch

,

while

,

for

loops, and function definitions.

<code>if grep fish /etc/shells
  echo Found fish
else if grep bash /etc/shells
  echo Found bash
else
  echo Got nothing
end</code>
<code>switch (uname)
  case Linux
    echo Hi Tux!
  case Darwin
    echo Hi Hexley!
  case '*'
    echo Hi, stranger!
end</code>
<code>while true
  echo "Loop forever"
end</code>
<code>for file in *.txt
  cp $file $file.bak
end</code>

4. Custom Prompt

Create a

fish_prompt

function in

~/.config/fish/config.fish

to display time, path, and Git status with colors and symbols.

<code># Example prompt function (simplified)
function fish_prompt
  set __prompt_data "["(date "+%H:%M:%S")"]"
  set __prompt_pwd (prompt_pwd)
  if git_is_repo
    set __branch (git_branch_name)
    set __git_info " ("$__branch": "(git status --short)")"
  else
    set __git_info ""
  end
  echo -n "┬─"$__prompt_data$__prompt_pwd$__git_info"\n╰─> $ "
end
</code>

5. Modify Greeting

Define a

fish_greeting

function to change the welcome message shown on startup.

<code>function fish_greeting
  echo "Hello friend!"
  echo "The time is "(set_color yellow; date +%T; set_color normal)" and this machine is called "$hostname
end</code>
Fish Shellcommand lineInstallationmacOSGit IntegrationpromptShell Customization
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.