Live data from Hacker News

Start all of your commands with a comma (2009)

rhodesmill.org

11–20 of 130 posts

Re: Start all of your commands with a comma (2009)

#11
If I unknowingly named my command the same as some system command and the custom command ends up earlier in my path it doesn't really cause any problems does it? I wasn't using that system command anyways, and my custom command is only going to take priority if my .bashrc file was run first.

Re: Start all of your commands with a comma (2009)

#12
I have used a similar windows trick. I wanted to add to the default window system a place for my library of tools. Most are "portable" cmd apps from various sources (sysinternals, nirsoft). I put them all into a directory called ] in the root of a drive.

Because of some common layout of keyboards the \ and ] are near each other, or in reach of left and right pinkies I can type \]\ before the name of the tools. This means I don't even have add a dir to the path.

I am sure this violates someone sensibilities but it has saved time over the years as a consultant when I had to deal with a wonky machine and owner did not want permanent install of diagnostic tools.

Re: Start all of your commands with a comma (2009)

#13
post #2

This is a good trick to avoid collisions with system commands. Anytime you add one of your own executables to PATH, prefix it with a comma (,). This way you avoid name collisions and have a handy way of seeing what commands are available on your system using tab completion (, then tab lists all of your personal executables)

Is this comment from a bot? You just reiterated everything from the article.

Re: Start all of your commands with a comma (2009)

#14
post #11

If I unknowingly named my command the same as some system command and the custom command ends up earlier in my path it doesn't really cause any problems does it? I wasn't using that system command anyways, and my custom command is only going to take priority if my .bashrc file was run first.

Until you use a different machine and accidentally type your command without realizing it's not there.

Re: Start all of your commands with a comma (2009)

#15
post #11

If I unknowingly named my command the same as some system command and the custom command ends up earlier in my path it doesn't really cause any problems does it? I wasn't using that system command anyways, and my custom command is only going to take priority if my .bashrc file was run first.

It can if you are executing programs that then try to execute those commands and get your commands instead.

Re: Start all of your commands with a comma (2009)

#16
post #11

If I unknowingly named my command the same as some system command and the custom command ends up earlier in my path it doesn't really cause any problems does it? I wasn't using that system command anyways, and my custom command is only going to take priority if my .bashrc file was run first.

Yes, all of that. And if you later decide to start using the system command, you just rename your custom command.

Re: Start all of your commands with a comma (2009)

#17
I do basically the same thing with any aliases or commands that I have just for me. Except I prefix with _ (an underscore.) Having some sort of prefix is extremely nice as it ensures you never override a built-in on accident, AND it makes it easy to tab complete just the ones that you want.

For example I have ‘_f’ aliased to a fuzzy find command that will launch vim on the selected files, and a different one for launching sql clients to various servers etc.

As a prefix, commas work great!

Re: Start all of your commands with a comma (2009)

#18

I do basically the same thing with any aliases or commands that I have just for me. Except I prefix with _ (an underscore.) Having some sort of prefix is extremely nice as it ensures you never override a built-in on accident, AND it makes it easy to tab complete just the ones that you want. For example I have ‘_f’ aliased to a fuzzy find command that will launch vim on the selected files, and a different one for laun…

Unfortunately zsh uses the underscore prefix heavily, _ results in hundreds of possible completions.

Re: Start all of your commands with a comma (2009)

#20
post #8

Clever trick. Too bad there's no good way to namespace commands. It would be interesting if you could have, for instance: $ mkdir -p /tmp/bin/my $ printf '%s\n%s\n' '#!/bin/sh' 'echo hello' > /tmp/bin/my/hello $ chmod 755 /tmp/bin/my/hello $ PATH="/tmp/bin:$PATH" $ my/hello hello

I don't know if I would actually recommend this, but it works:

    $ touch foo::bar
    $ chmod +x foo::bar
    $ ./foo::bar && echo $?
It's an empty file so it does nothing, but most shells' lexers should be smart enough to not try and lex '::'.

Edit: Forgot to mention, this also works with bash functions and aliases. I'm not sure if POSIX sh will allow it. You can also do things like this (again, not sure I'd recommend it):

    $ alias +x='chmod +x'
Post reply on HN