abbr_path.fish is a tiny fish shell utility that wraps fish's native abbr to create path abbreviations.
Define a short alias once, and from then on it expands to a real filesystem path anywhere in a command.
abbr_path f_cf ~/.config/fish/config.fish❯ nvim f_cf⇥
❯ nvim ~/.config/fish/config.fish█It works as an argument to any command: cat, cp, ls, nvim, source, you name it.
There are plenty of great tools for jumping around a filesystem (z, zoxide, fzf, …), and abbr_path can stand in for some of them, but that wasn't the motivation.
The goal is to make your frequently-used files and directories available as arguments to any command.
Instead of remembering (or cd-ing toward) a deep path, you type a short mnemonic and let fish expand it in place:
❯ cat f_cf⇥ → cat ~/.config/fish/config.fish█
❯ ls f_⇥ → ls ~/.config/fish/█
❯ cp x D_⇥ → cp x ~/Downloads/█Because it builds on abbr --position=anywhere, the expansion is inline, visible, and editable before you hit enter. There's no magic, no subshell, just fish doing what it already does well.
fisher install ndonfris/abbr_path.fishManual installation (without fisher)
curl -L https://raw.githubusercontent.com/ndonfris/abbr_path.fish/master/conf.d/abbr_path.fish \
-o ~/.config/fish/conf.d/abbr_path.fishabbr_path <ABBR_NAME> <PATH> [OPTIONS]| Argument | Description |
|---|---|
<ABBR_NAME> |
The short alias you'll type. A trailing-marker like _ reads nicely. |
<PATH> |
The directory or file the alias expands to. |
| Options | Description |
|---|---|
--tilde |
Create the abbr with $HOME replaced in <PATH> using a tilde (~) |
--add-cd-abbr [STR?] |
Create an added alias prefixed via cd<ABBR_NAME> with any trailing _ removed |
--add-editor-abbr [STR?] |
Create an added alias prefixed via $EDITOR<ABBR_NAME> with any trailing _ removed |
--warn-missing-slash |
Show a warning when abbr_path is called with directory missing trailing / |
| Universal Variables | Description |
|---|---|
ABBR_PATH_EDITOR |
Override what --add-editor-path abbr prefix value is used for $EDITOR |
ABBR_PATH_DEFAULT_OPTS |
Options to pass to every abbr_path function call |
Run abbr_path --help for a built-in cheat sheet of examples.
abbr_path f_ '~/.config/fish/'
# if you want to keep `~/.config/fish/` expansion exactly either
# >_ abbr f_ '~/.config/fish/'
# >_ abbr f_ ~/.config/fish/ --tildeNow f_ expands to ~/.config/fish/ wherever it appears:
❯ cd f_⇥
❯ cd ~/.config/fish/█
❯ ls f_⇥
❯ ls ~/.config/fish/█abbr_path f_cf '~/.config/fish/config.fish'❯ nvim f_cf⇥
❯ nvim ~/.config/fish/config.fish█
❯ cat f_cf⇥
❯ cat ~/.config/fish/config.fish█A loose convention keeps a growing set of abbreviations memorable: a leading letter for the "area", _ as the marker, and extra letters to drill in:
# fish config
abbr_path f_ '~/.config/fish/'
abbr_path f_f '~/.config/fish/functions/'
abbr_path f_c '~/.config/fish/completions/'
abbr_path f_cd '~/.config/fish/conf.d/'
abbr_path f_cf '~/.config/fish/config.fish'
# common config folders
abbr_path c_ '~/.config/'
abbr_path n_ '~/.config/nvim/'
abbr_path t_ '~/.tmux/'
abbr_path t_cf '~/.tmux/tmux.conf'
# project locations
abbr_path r_ '~/repos/'
abbr_path p_ '~/projects/'
abbr_path w_ '~/work/'
# asset locations
abbr_path D_ '~/Downloads/'
abbr_path P_ '~/Pictures/'
abbr_path V_ '~/Videos/'Tip
Directory paths read best with a trailing /, since fish completes into them naturally,
so f_⇥ becomes ~/.config/fish/ ready for the next path segment.
Use the related --tilde flag to rewrite an absolute, $HOME-prefixed path back to ~ before it's stored.
Handy if you:
- build the path from
$PWDor a completion - don't want to quote
<PATH>arguments
abbr_path f_ /home/you/.config/fish/ --tilde # stored as ~/.config/fish/❯ f_⇥
❯ ~/.config/fish/█Pass --add-editor-abbr to abbr_path, when <PATH> argument is a file, and you want extra companion abbreviations added for opening the editor straight into the file.
Warning
Must either have $ABBR_PATH_EDITOR or $EDITOR set
# assume `$EDITOR` is set to `nvim`
abbr_path f_cf '~/.config/fish/config.fish' --add-editor-abbr --add-editor-abbr='f'❯ nvimf_cf⇥
❯ nvim ~/.config/fish/config.fish█
❯ nvimf⇥
❯ nvim ~/.config/fish/config.fish█Behavior & rules:
- The editor-abbr is named
$EDITOR+ your abbr name with one trailing_stripped - One or more
--add-editor-abbrswitches can be used.- when
--add-editor-abbris seen without a value given, it assumes that it should use the abbr name (with any trailing_) - when
--add-editor-abbr=VALUEis seen, anabbr nvimVALUEis created expanding tonvim PATH
- when
- It expands only in command position, so it acts like a normal command and never interferes with
f_used mid-line.
Pass --add-cd-abbr and abbr_path creates extra, companion abbreviation for jumping straight into a directory, on top of the usual anywhere-expansion.
abbr_path f_ '~/.config/fish/' --add-cd-abbrYou now have two abbreviations from that one line:
| Type | Expands to | Position | Use it for |
|---|---|---|---|
f_ |
~/.config/fish/ |
anywhere | the path as an argument to any cmd |
cdf |
cd ~/.config/fish/ |
command | hopping into the directory |
❯ cdf⇥
❯ cd ~/.config/fish/█Behavior & rules:
- The cd-abbr is named
cd+ your abbr name with one trailing_stripped (A name without a trailing_, e.g.proj, becomescdproj.) - One or more
--add-cd-abbrswitches can be used.- when
--add-cd-abbris seen without a value given, it assumes that it should use the abbr name (with any trailing_) - when
--add-cd-abbr=VALUEis seen, anabbr cdVALUEis created expanding tocd PATH
- when
- The
cdprefix keeps it namespaced, so it won't collide with yourf_path abbreviation or with real commands. - It expands only in command position, so it acts like a normal command and never interferes with
f_used mid-line. - It's only meaningful for directories. Pointing it at a file produces a
cdthat errors at runtime, so reserve--add-cd-abbrfor folder paths.
This flag is generally meant to be used in the $ABBR_PATH_DEFAULT_OPTS universal variable.
set -Ux ABBR_PATH_DEFAULT_OPTS --warn-missing-slash❯ abbr_path f_f '~/.config/fish/functions' # WARNING!
❯ abbr_path f_f '~/.config/fish/functions/' # No warning.
❯ abbr_path f_cf '~/.config/fish/config.fish' # No warning. <PATH> is a fileSet these universal variables in an interactive session, and they will be used across every abbr_path call.
The editor name to prepend the <ABBR_NAME> or --add-editor-abbr
EXAMPLE:
❯ # interactive session
❯ set -Ux ABBR_PATH_EDITOR emacs
❯ abbr_path f_cf '~/.config/fish/config.fish' --add-editor-abbr=f --add-editor-abbr=F
❯ emacsf⇥
❯ emacs ~/.config/fish/config.fish█
❯ emacsF⇥
❯ emacs ~/.config/fish/config.fish█The arguments to append to the end of $argv for every abbr_path function call.
This variable can be useful to avoid passing --tilde for every abbr_path usage, if you don't want to quote the <PATH> argument.
You can also enable warnings for abbr_path locations that didn't include trailing / for folders.
❯ # interactive session
❯ set -Ux ABBR_PATH_DEFAULT_OPTS --tilde --warn-missing-slash
❯ abbr_path f_cf ~/.config/fish # WARNING
❯ abbr_path f_cf ~/.config/fish/ # NO WARNINGabbr_path creates a session abbreviation. To keep your favorites across shells, add the abbr_path calls to a file that fish sources on startup, e.g. ~/.config/fish/config.fish or a dedicated ~/.config/fish/conf.d/my_paths.fish.
Full example: ~/.config/fish/conf.d/abbr_paths.fish
## All definitions `abbr` usages from fisher plugin `ndonfris/abbr_path.fish`
##
## Located in ~/.config/fish/conf.d/abbr_paths.fish
##
status is-interactive || return
# OPTIONAL: function to edit this file
function abbr_pathed -d 'function to edit `conf.d/abbr_paths.fish`'
$EDITOR ~/.config/fish/conf.d/abbr_paths.fish
and source ~/.config/fish/conf.d/abbr_paths.fish
end
# fish
abbr_path f_ '~/.config/fish/' --add-cd-abbr
abbr_path f_f '~/.config/fish/functions/' --add-cd-abbr
abbr_path f_f '~/.config/fish/completions/' --add-cd-abbr
abbr_path f_cd '~/.config/fish/conf.d/' --add-cd-abbr
abbr_path f_cf '~/.config/fish/config.fish'
# nvim
abbr_path n_ ~/.config/nvim/ --add-cd-abbr --tilde
abbr_path n_l ~/.config/nvim/lua/ --add-cd-abbr --tilde
abbr_path n_n ~/.config/nvim/init.lua --tilde
# ~/.config
abbr_path c_ '~/.config/' --abbr-cd-abbr
# Other
abbr_path D_ '~/Downloads/' --add-cd-abbr
abbr_path P_ '~/Pictures/' --add-cd-abbr
abbr_path V_ '~/Videos/' --add-cd-abbr
abbr_path R_ '~/repos/' --add-cd-abbrUnder the hood, abbr_path is a thin wrapper around fish's own abbreviation engine:
abbr -a $name --set-cursor --position=anywhere -- $path%--position=anywherelets the abbreviation expand mid-command, not just as the first token.--set-cursor(%marker) drops your cursor right after the expanded path, ready to keep typing.
That's the whole trick: no background process, no shell hooks.
fisher installation
fisher remove ndonfris/abbr_path.fishcurl installation
emit abbr_path_uninstall
rm -f ~/.config/fish/conf.d/abbr_path.fishImportant
Remove any saved abbr_path calls from your config before uninstalling, otherwise fish
will try to run a command that no longer exists on startup. To find them:
cd ~/.config/fish/ && grep -rE 'abbr_path' **/*.fishContributions are welcome! Please open an issue or submit a pull request.


