Robles.dev

Start your aliases with a comma

In bash, you can start your alias and your commands with a comma in order to ease the completion.

That’s it. Suppose that you have a very complex command that you use sometimes, but not frequently. Here is a example that I use sometimes:

find . -maxdepth 1 -name "*.dot" -print0 | while IFS= read -r -d "" f; do dot -Tsvg "$f" -o "${f%.dot}.svg" && rm "$f"; done

This command finds all the dot files within 1 depth of the current directory, converts them to a svg, and removes the original dot file. As you can see, the worded explanation is as long as the command, so obviously, I define an alias and save it in .bashrc:

alias dots2svg='find . -maxdepth 1 -name "*.dot" -print0 | while IFS= read -r -d "" f; do dot -Tsvg "$f" -o "${f%.dot}.svg" && rm "$f"; done'

The issue with this alias is that if I remember it barely, I would try to use autocompletion, but if I type just the ’d’ and hit Tab there are 121 possible commands.

In contrast, let’s suppose that I name this command like ‘,dots2svg’. Commands that start with a comma are totally valid, and the good thing is that none of the regular commands in bash use it. So, if I type the command and hit Tab again, I get a list of all my commands which is already great, and since the list is so small, I can clearly see which could be.

This is a quick and easy trick, that greatly improves your workflows

#TIL #Tools