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.
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:
brew install fishNote the installation path shown in the screenshot; you may need it later.
2. Switching Shells
2.1 Manual Switch
Start Fish temporarily: fish Exit back to the previous shell with:
exit2.2 Set as Default Shell
Add Fish to /etc/shells and change the default with chsh: sudo vim /etc/shells Then run:
chsh -s /opt/homebrew/Cellar/fish/3.6.1/bin/fishTo 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 -> or partially with Alt + ->.
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.
fish</code>
<code>fish_config3.5 Custom Configuration File
Edit ~/.config/fish/config.fish to add aliases, functions, or other settings. Example aliases for Git:
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"3.6 Easy‑to‑Read Syntax
Fish uses a high‑level syntax. Examples include if, switch, while, for loops, and function definitions.
if grep fish /etc/shells
echo Found fish
else if grep bash /etc/shells
echo Found bash
else
echo Got nothing
end switch (uname)
case Linux
echo Hi Tux!
case Darwin
echo Hi Hexley!
case '*'
echo Hi, stranger!
end while true
echo "Loop forever"
end for file in *.txt
cp $file $file.bak
end4. Custom Prompt
Create a fish_prompt function in ~/.config/fish/config.fish to display time, path, and Git status with colors and symbols.
# 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"
╰─> $ "
end5. Modify Greeting
Define a fish_greeting function to change the welcome message shown on startup.
function fish_greeting
echo "Hello friend!"
echo "The time is "(set_color yellow; date +%T; set_color normal)" and this machine is called "$hostname
endSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
