in ,

Start all of your commands with a comma (2009), Hacker News

  by Brandon Rhodes   • Home

)

Date:

PATH

(August) Tags: computing

  Like many Unix users,   I long ago created a ~ / bin / directory in my home directory   and added it to my

  so that I could supplement   the wonderfully rich set of basic Unix commands   with some conveniences and shell scripts of my own devising.

  The problem, of course, was the chance of collision.   Because my shell script names   tended to be short and pithy collections of lowercase characters,   just like the default system commands,   there was no telling when Linux would add a new command   that would happen to have the same name as one of mine.   This was actually not very likely on,   say, a System V Revision 3 workstation in the s,   but the trouble became quite a bit more acute   when I moved into the world of Debian.   Red Hat never really worried me,   Because they packaged (comparatively) so little software.   But Debian today supports a huge number of commands;   my modest Ubuntu laptop shows several thousand available:

($) (apt) (apt) ) – (file (search) (search) – (x) (x) ‘ (^ / usr

 
 /    bin 
 
 /    [^/]      $ '  |   wc   -   l      

  The solution was obviously to adjust my command names   in such a way that they were still easy to type,   but would never be chosen as system command names.   For me, “easy to type” means not having to use the shift key,   and very few characters turned out to be available,   unshifted, on a modern keyboard.   The lower-case letters   are the very characters used in system commands;   brackets, backslashes, the colon, the back-tick, and the single-tick   all had a special meaning to the shell;   and the slash and dot characters both mean something special   in a filename.   (The slash divides directory names from filenames,   and thus cannot appear in a filename itself,   While the dot means “hide this file from normal browsing”   if it leads the name,   and separates a file from its extension in many other cases.)

  There was but one character left: the simple, modest comma.

  A quick experiment revealed in a flash   that the comma was exactly the character   that I had been looking for!   Every tool and shell that lay in arm's reach   treated the comma as a perfectly normal   and unobjectionable character in a filename.   By simply prefixing each of my custom commands   with a comma,   they became completely distinct from system commands   and thus free from any chance of a collision.

  And, best of all,   thanks to the magic of tab-completion,   it became very easy to browse my entire collection of commands.   When trying to remember which of my commands   are available in my ~ / bin / directory on a given system,   or when simply trying to remember what   some of my commands are called,   I simply type a comma followed by tab   and my list of commands appears:

$, «tab» , complete-scp, go-thpgp, range , complete-ssh, gr, svn-store-password , coreoff, hss, umount , coreon, mount-thpgp , find, mount-twt

  I heartily recommend this technique   to anyone with their own ~ / bin / directory   who wants their command names kept clean, tidy,   and completely orthogonal   to any commands that the future might bring to your system.   The approach has worked for me for something like a decade,   so you should find it immensely robust.   And, finally, it's just plain fun.

                    comments powered by

©

Read More) Brave Browser

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

Fun with GTFS & Clojure, Hacker News

[FREE]Essential Coding Interview Questions + Solutions + Excercise