obsidian/wiki/concepts/fish-abbr-patterns.md
2026-04-18 22:04:01 +01:00

4 KiB

title aliases tags sources created updated
Fish Shell — abbr vs alias Patterns
fish-abbreviations
fish-abbr
fish-alias-vs-abbr
fish
shell
dotfiles
terminal
abbr
alias
daily/2026-04-17.md
2026-04-17 2026-04-17

Fish Shell — abbr vs alias Patterns

Fish shell offers two ways to create command shortcuts: abbr (abbreviations) and alias. The choice between them affects transparency and interaction with third-party Fish plugins like forgit. Using abbr for expanded commands and alias for invisible substitutions is the idiomatic Fish pattern.

Key Points

  • abbr expands in the command line before execution — the user sees the full command in the prompt history, making actions transparent and auditable
  • alias runs as a hidden substitution — the original alias name appears in history, not the underlying command
  • Use abbr for git/docker/uv shortcuts where seeing the expanded command is useful; use alias for transparent replacements like ls→lsd, cat→bat
  • Fish abbreviations can conflict with forgit plugin functions — forgit defines gco, grb, glo, etc. as interactive functions; naming an abbreviation the same will shadow the forgit function
  • Resolve forgit conflicts by renaming your abbreviation (e.g., gcogch for git checkout)

Details

abbr vs alias Decision Table

Use case Use Why
git checkoutgch abbr Expands visibly — you see git checkout in prompt
docker composedc abbr Expands — clear what's running
lslsd alias Should be invisible — ls stays in history
catbat alias Transparent replacement — looks like cat
forgit interactive commands none Provided by forgit plugin — don't shadow

Defining Abbreviations

# In ~/.config/fish/config.fish or ~/.config/fish/abbreviations.fish

# Git shortcuts (expand visibly)
abbr --add gst 'git status'
abbr --add gch 'git checkout'    # not gco — conflicts with forgit
abbr --add gpl 'git pull'
abbr --add gps 'git push'
abbr --add glo 'git log --oneline'  # renamed — forgit uses glo too

# Docker
abbr --add dc 'docker compose'
abbr --add dcu 'docker compose up -d'
abbr --add dcd 'docker compose down'

# uv (Python package manager)
abbr --add uvr 'uv run'
abbr --add uvs 'uv sync'

Defining Aliases (Transparent Replacements)

# In ~/.config/fish/config.fish

# These should feel like the original command
alias ls='lsd'
alias cat='bat --paging=never'
alias grep='rg'
alias find='fd'

Forgit Conflict Resolution

forgit (interactive git fzf plugin) defines these functions by default:

forgit function What it does
gco Interactive git checkout
grb Interactive git rebase
glo Interactive git log
gbl Interactive git blame
gd Interactive git diff

If you have abbreviations with the same names, the abbreviation wins on expansion but the forgit function is still reachable by full name. The practical fix: rename your abbreviation to avoid the conflict (gcogch, gloglg).

Viewing All Current Abbreviations

abbr          # list all abbreviations
alias         # list all aliases
functions     # list all functions (includes forgit)

Persistence

Both abbr and alias defined in config.fish persist across sessions. abbr --add called interactively creates a universal variable that also persists — but storing abbreviations in config.fish is more portable for dotfiles repos.

Sources

  • daily/2026-04-17.md — Fish abbreviations setup session; abbr chosen over alias for git/docker/uv commands; gco/grb/glo conflicts with forgit resolved by renaming abbreviations; transparent replacements (ls→lsd, cat→bat) kept as alias