How much is the Fish?

Posted on Jun 8, 2022

I’m not crazy about fish. I do eat it sometimes for the good fats, but I don’t really enjoy it. But wait, this isn’t about food. Now, Scooter is pretty good.

I dig fish, the linux shell. I’ve been running it for a good few years now, and have not really looked back (to Bash). But this isn’t about which is better, they are all good, and different.

“You complete me." Yeah, if there’s a good mention with fish, it’s completions. Very easy to add your own as well. But this isn’t about that either, maybe I’ll cover that later, but about abbreviations.

This is another command I use quite a bit, abbr, short for the obvious. It’s much like a bash alias, but not exactly the same, but it completes commands for you.

Take some frequent command you use, and abbreviate it. Let’s say,

sudo systemctl is something I often type, thus,

$ abbr --add sus sudo systemctl

Next time you type sus (and enter) it will execute it just like an alias.

Now type sus (and a following space), it will complete it, showing the completed command (and also autosuggest, like fish normally does).

So I my case, on this test example, it showed the below, as soon as I typed sus (restart dhcpcd from fish autosuggest, built in automagic crtl-r)

~> sudo systemctl restart dhcpcd

(Quick note on autosuggest, it doesn’t actually complete that, but displays it giving you the option to complete it, but tabbing or arrowing, leaving the cursor before the suggest. In fish completion works ‘as you type’).

Just typing abbr lists current ones:

abbr -a -U -- gcm 'git commit'
abbr -a -U -- gco 'git checkout'
abbr -a -U -- sus 'sudo systemctl'
abbr -a -U -- vc 'sudo /opt/vc/bin/vcgencmd'

Here’s the rest (from the –help):

abbr - manage fish abbreviations

abbr --erase WORD ...
abbr --rename [SCOPE] OLD_WORD NEW_WORD
abbr --show
abbr --list
abbr --query WORD ...

Happy fishin’!