by Joel Tari

One Easy Step to Improve Custom Command Naming on Unix Systems

Achieve improved command management by prepending the name of your scripts or aliases with a comma.

Here are a few examples:

  • alias ,n='cd'
  • ,g
  • ,f
  • ,gst
  • ,r

But why ?

Before diving into the details, do note that we can ! Having a terminal command that starts with a comma is a legit shell syntax.

Prevent conflicts

Any command added in your PATH is a liability as it conflicts or bears the future potential to conflict with a namesake command provided by a third party.

Basically, it relates to any executable added by third party on your $PATH environment variable. On a development machine, the content of the $PATH can grow rapidly as any program can decide to add some names to the path.

To explore this issue on your system, run echo $PATH | tr : '\n' in the shell. You may find the usual suspects such as /usr/bin/ and /home/USER/.local/bin but also some less expected ones.

Let’s count how many commands we have access to :

echo $PATH | tr : '\n' | xargs -I _ ls _ | uniq | wc -l

We just lay out the content of each of the directories in PATH and count how many commands coexist in your shell session. The result can be several thousands, sometimes even north of 5k. And these are just the existing commands.

Assume that you have an alias (alias rg=ranger) in your rc file. The rg shell command acts as you would expect until some months down the line you inadvertently install rg, a.k.a. ripgrep, because of another program depending on it. Things start breaking from that point in unforeseen ways.

Easier and faster completion

If that isn’t obvious, the comma naming convention splits your command namespace in 2, the commands starting with , and the rest. This information can be used to your advantage when you forgot the name of a script you previously wrote:

“I did make a script that do X, Y and Z some years ago, but I don’t remember the exact name…”

By virtue of the comma trick, we know that it starts with a comma, thus we can type , and <Tab> to trigger the completion system of our shell and look for our script against the limited set of our custom commands (versus all the commands in the shell).

It is even more powerful when combined with a fuzzy-finder such as fzf. I will have a post on fuzzy finders coming soon.

The comma key is close to the home row

Typing cd all day is boring and unintuitive on qwerty keyboards ! I have listed alias ,n='cd' as faster-typed alternative.