Operations 13 min read

Master Fish Shell: Installation, Custom Prompt, and Powerful Features

Learn how to install Fish Shell on macOS, switch from Bash or Zsh, set it as the default shell, explore its syntax highlighting, auto‑completion, web‑based configurator, custom prompts, and useful configuration snippets, while avoiding common pitfalls.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Fish Shell: Installation, Custom Prompt, and Powerful Features

Introduction

When we talk about a command‑line interface ( CLI), the most common shells are Bash and zsh. A shining star among them is Fish Shell, praised for its modern design and powerful features, marketed as “Finally, a command line shell for the 90s”. Its main features include:

Many useful functions are integrated by default, with limited configuration.

Command‑line syntax highlighting; errors appear in red.

Smart suggestions.

Visual configuration via a web page.

This article briefly introduces the various features and advantages of Fish Shell, shows how to start using and customizing it, and demonstrates why both beginners and experienced users can enjoy a more pleasant and efficient command‑line experience.

Installation

First, install fish. The example below shows the macOS installation method using Homebrew; other platforms are covered in the official documentation.

brew install fish
The highlighted part in the screenshot shows the installation path of fish . Remember it for later use.

Switching

Manual switching

By default the terminal uses Bash or zsh. Switch to Fish with the following command:

fish
To exit Fish, run exit .
exit

Set as default shell

First confirm the Fish installation path (shown in the installation logs). Then add the path to /etc/shells to avoid the “non‑standard shell” error:

sudo vim /etc/shells

Switch the default shell with chsh -s:

chsh -s /opt/homebrew/Cellar/fish/3.6.1/bin/fish

After reopening the terminal, Fish becomes the default shell. To revert, run: chsh -s /bin/zsh or

chsh -s /bin/bash

Useful Features

Command‑line syntax highlighting

Fish highlights syntax as you type, detecting potential errors before execution. Highlights include:

Valid commands appear in blue.

Invalid commands appear in red.

Valid paths are underlined.

Mismatched brackets or commas are highlighted.

Auto‑completion suggestions

Fish provides command‑completion suggestions in a subtle gray after you type a few characters. The suggestions may be generated by Fish or come from command history.

Press -> to accept a suggestion, or Alt -> to accept part of it.

Tab completion

Press Tab after typing a few letters to see possible completions for a command.

Typing git then Tab lists all git sub‑commands with descriptions.

Typing git (with a space) and Tab shows all git commands.

Pressing Tab after a dash ( -) shows possible git commit options.

Web‑based configurator

Fish can open a browser‑based UI to configure themes, prompts, functions, variables, history, and key bindings.

Enter Fish and run fish_config to launch the UI.

fish
fish_config

Select a theme color; many defaults are provided, or create a custom one.

Configure the prompt; custom prompts require editing configuration files.

Custom prompt

Define a fish_prompt function in ~/.config/fish/config.fish to create a personalized prompt.

function git_is_repo -d "检测当前目录是否是 git 仓库"
  test -d .git
  or begin
    set -l info (command git rev-parse --git-dir --is-bare-repository 2>/dev/null)
    and test $info[2] = false
  end
end

function git_branch_name -d "获取当前分支名"
  git_is_repo; and begin
    command git symbolic-ref --short HEAD 2>/dev/null;
    or command git show-ref --head -s --abbrev | head -n1 2>/dev/null
  end
end

function fish_prompt -d "终端提示符"
  set -f __prompt_data (set_color -o 46C74B)"["(date "+%H时%M分%S秒")(set_color -o 46C74B)"]"
  set -f __prompt_pwd " "(set_color 00FF00)(prompt_pwd --full-length-dirs=10)
  if git_is_repo
    set -g __fish_git_prompt_char_stagedstate "●"
    set -g __fish_git_prompt_char_dirtystate "✚"
    set -g __fish_git_prompt_char_cleanstate "✔"
    __fish_git_prompt 2 >/dev/null;
    set -f __informative_status (set_color -o bryellow)(__fish_git_prompt_informative_status)
    set -f __branch (set_color brred)(git_branch_name)
    set -f __prompt_git_info (set_color FF4BFF)" ("(git_branch_name)": "(set_color red)$__informative_status(set_color FF4BFF)")"
  else
    set -f __prompt_git_info ""
  end
  echo (set_color 00BA00)"┬─"$__prompt_data$__prompt_pwd$__prompt_git_info(set_color normal)
  echo (set_color 00BA00)"╰─>"(set_color FF635C)"\$ "
end

if status is-interactive
end

Greeting message

Override the default greeting by defining a fish_greeting function.

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
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

fish-shellShellcommand-linemacOScustomization
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

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.