Fish Shell Guide¶
Fish (Friendly Interactive Shell) is a smart and user-friendly command line shell for Linux, macOS, and other systems. Unlike bash or zsh, Fish is designed to be interactive out of the box with no configuration required.
Key Features¶
Out of the Box - Syntax highlighting - Autosuggestions based on history - Tab completions - Web-based configuration tool
Modern Design - No need to learn shell scripting for basic configuration - Sane defaults - Colorful prompt
Installation¶
macOS
brew install fish
Ubuntu/Debian
sudo apt update
sudo apt install fish
Fedora
sudo dnf install fish
Set as default shell
chsh -s /usr/bin/fish
Configuration¶
Config File Location¶
- User config:
~/.config/fish/config.fish
Using the Web UI¶
fish_config
Set Theme¶
fish_config theme choose "Dracula"
Common Commands¶
Aliases (similar to bash)¶
# Create an alias
alias ll 'ls -lah'
# Make it persist (add to config.fish)
alias ll 'ls -lah'
# Then save:
funcsave ll
Abbreviations (recommended over aliases)¶
# Abbreviations expand after pressing space
abbr --add g git
abbr --add gs git status
abbr --add ga git add
abbr --add gc 'git commit -m'
abbr --add gp git push
# Make persistent
funcsave g
Functions¶
# Create a function
function ll
ls -lah $argv
end
# Save for future sessions
funcsave ll
Useful Functions¶
Git branch in prompt¶
function fish_git_prompt
if git rev-parse --git-dir >/dev/null 2>&1
set -l branch (git symbolic-ref --short HEAD 2>/dev/null; or git rev-parse --short HEAD 2>/dev/null)
if test "$branch"
echo " ($branch)"
end
end
end
# Add to prompt in config.fish
set -g fish_prompt_dirty " ✗"
set -g fish_prompt_clean " ✓"
Quick directory navigation¶
# cd to directory and list contents
function cl
cd $argv; and ls
end
Key Differences from Bash¶
| Feature | Bash | Fish |
|---|---|---|
| Variables | VAR=value |
set VAR value |
| Export | export VAR |
set -x VAR |
| Arrays | arr=(one two) |
set arr one two |
| Conditionals | if [ $x = "y" ] |
if test $x = "y" |
| Loops | for i in *.txt |
for i in *.txt |
| Functions | function name() {} |
function name\nend |
Environment Variables¶
# Set (temporary)
set PATH $PATH /usr/local/bin
# Set persistently (add to config.fish)
set -gx EDITOR vim
# Unset
set -e VARIABLE_NAME
Tips & Tricks¶
Disable greeting¶
set fish_greeting ""
Use Starship prompt¶
# Install starship
brew install starship
# Add to config.fish
starship init fish | source
Search history¶
# Up/Down arrows search history
# Or use Ctrl+R for reverse search
Auto-cd (no need to type cd)¶
# Fish auto-cds to directories just by typing the path
/home/user/projects
# Automatically cd into it
Wildcards¶
# List all files
ls **/*.txt
# Recursive search
Troubleshooting¶
Fish not starting
# Check for syntax errors in config.fish
fish -n
List all functions
bash
Disable functions bracketed paste mode
set fish_bracketed_paste disabled