← nunq.net

fish abbreviations not auto-saving

published on 10 April 2023

Although the version that removed this feature was already released in January, I only noticed it now.

So just in case anyone hasn't noticed yet or in case I forget it: The fish shell no longer treats abbreviations as universal variables since version 3.6.0, because abbreviations are now built-ins, which comes with a lot of improvements which I'll mention later (among others they're faster now), but first the stuff that broke.

When you run abbr -a getip 'curl ifconfig.me' for example, the abbreviation is no longer automatically added to your config and thus persistent across sessions, it will only be accessible in the current session. Thus, since that release it has to be added manually to ~/.config/fish/config.fish. Just append this line:

abbr -a -- getip 'curl ifconfig.me'

The double dash tells the shell to stop processing arguments, this is useful if you want an abbreviation that starts with a dash, e.g. -X. I just do it because the old fish version stored them like this.

new features

Now for the improvements, it's possible to use abbreviations anywhere now, not just at the beginning of the prompt, for example

abbr -a N --position anywhere --set-cursor "% | nvim"

To easily pipe stuff into neovim with just N, or

abbr -a eachfile --set-cursor "$(string join \n -- 'for f in *' 'test -f $f || continue' '%' 'end')"

To generate the boilerplate for loop to iterate over files in the current directory. When expanded, the cursor is put where the percent sign is (you can also set which character to use, but % is the default).

For more info including how to use functions with abbreviations, see the full v3.6 docs here.