abbr
Define and expand command abbreviations
TLDR
Add a new abbreviation
Rename an existing abbreviation
Erase an existing abbreviation
Import the abbreviations defined on another host over SSH
SYNOPSIS
abbr [options] [NAME [VALUE]]
abbr --add NAME VALUE
abbr --erase NAME...
abbr --show [NAME...]
PARAMETERS
--add, -a NAME VALUE
Adds a new abbreviation mapping NAME to VALUE.
--erase, -e NAME...
Erases one or more existing abbreviations by NAME.
--set, -s NAME VALUE
Changes the value of an existing abbreviation NAME to VALUE.
--rename, -r OLD_NAME NEW_NAME
Renames an existing abbreviation from OLD_NAME to NEW_NAME.
--show, -S [NAME...]
Displays all or specific abbreviations, showing their name and value.
--list, -l [NAME...]
Lists abbreviations in a machine-readable format, suitable for scripting.
--function, -f NAME...
Converts one or more abbreviations into a function. This is often used to get more complex behavior than simple expansion allows.
--global, -g
Makes the abbreviation permanent by saving it to the fish configuration, accessible in future sessions.
--session, -x
Makes the abbreviation temporary, valid only for the current shell session and not saved.
--description TEXT
Adds a descriptive text to the abbreviation, visible with abbr --show.
--regex REGEX
Filters the output of --show or the targets of --erase/--disable/--enable/--toggle by a regular expression.
--disable, -D NAME...
Temporarily disables one or more abbreviations without erasing them.
--enable, -E NAME...
Enables one or more previously disabled abbreviations.
--toggle NAME...
Toggles the enabled/disabled state of one or more abbreviations.
--reset
Erases all current abbreviations.
--help
Displays help information for the abbr command.
DESCRIPTION
The abbr command is an integral part of the fish (friendly interactive shell), used for managing command abbreviations. Unlike traditional shell aliases that substitute a command during execution, abbr expands a short keyword into a longer command before it is parsed by the shell. This pre-parsing expansion allows for features like argument completion on the expanded form, which is a significant advantage over aliases. It helps users type less for frequently used commands or create memorable shortcuts. Abbreviations can be defined for the current session or saved globally to persist across shell sessions. They are a powerful tool for streamlining workflow and enhancing productivity within the fish shell environment.
CAVEATS
The abbr command is exclusive to the fish shell. It is not a standard Unix/Linux command and will not work in other shells like Bash or Zsh. Users of other shells should look for similar functionality provided by their shell (e.g., alias or functions).
ABBREVIATION VS. ALIAS
While conceptually similar in saving typing, abbr in fish differs significantly from the alias command found in Bash or Zsh. An abbr expands the abbreviation into its full form before the command line is parsed. This means that command-line completions and argument handling work on the expanded command, not the abbreviation itself. For example, if you have abbr gc 'git commit', typing gc -m will offer completions relevant to git commit, whereas an alias might not provide the same context.
PERSISTENCE
By default, abbreviations defined without the --global or --session flags are temporary. To make an abbreviation persistent across shell sessions, the --global (-g) flag must be used when adding it. Fish saves global abbreviations in its configuration directory (typically ~/.config/fish/abbreviations), ensuring they are loaded automatically upon shell startup.
HISTORY
The abbr command is a core feature of the fish shell, designed to enhance user experience and productivity. It has been an integral part of fish since its early development, reflecting the shell's philosophy of being user-friendly and feature-rich out-of-the-box. Its implementation provides a distinct advantage over simple aliases by allowing pre-execution expansion and completion.