10 ms·
Start all of your commands with a comma (2009)
- heynowheynow 4y agoCool. I have a script that creates new ~/bin scripts that checks for collisions locally (functions, builtins, and executables) and in linux distros. For example, I have a ~/bin/up script on every box and platform to install updates. So far so good on collisions.
- reidjs 4y agoThis 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)
- deleted 4y ago[deleted]
- _blz2 4y agoIs this comment from a bot? You just reiterated everything from the article.
- heleninboodler 4y agoThis is an explanation that the parent comment simply reiterated the point of the article rather than adding content.
- scubbo 4y agoThis is a link to a story titled "This is the title of this story, which is also found several times in the story itself": https://stuff.mit.edu/people/dpolicar/writing/prose/text/titleOfTheStory.html https://stuff.mit.edu/people/dpolicar/writing/prose/text/tit...
- acomjean 4y agoYou are right, but I’m guessing a lot of people don’t read the linked article. It’s a pretty good summation. Though it doesn’t mention using ~/bin. I use that but don’t add it to my path, so I have to explicitly call my scripts. The comment history suggests it isn’t a bit though.
- behnamoh 4y agoRelated to GP, here's an interesting article: https://rhodesmill.org/brandon/2009/commands-with-comma/ https://rhodesmill.org/brandon/2009/commands-with-comma/
- potiuper 4y ago
- bravasaurus 4y agoThat was long enough ago that I think it’s worthy of being reposted. It was new to me.
- alar44 4y agoOh no it was posted over 2 years ago
- dang 4y agoReposts are ok after a year or so. This is in the FAQ: https://news.ycombinator.com/newsfaq.html https://news.ycombinator.com/newsfaq.html. Could you please review the site guidelines at https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html and stick to them? Your last sentence there breaks more than one of the rules.
- potiuper 4y agoAgain, to reiterate, the original comment was not a statement that this should not have been reposted. I am not sure how I could make that clearer? I have read the site guidelines. Many of them are subjective and inconsistent with unknown applicability. If you, as the administrator, are unable to accept that evaluation, then please just delete this account and all associated posts.
- Taywee 4y agoClever 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
- eurasiantiger 4y agoJust add another comma. Of course, this needs some deeper magic to work :) ,my,hello
- woodruffw 4y agoI 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'
- jwilk 4y ago> mkdir -p /tmp/bin/my This is not a secure way of using /tmp.
- Taywee 4y agoSure, but that's not the point. It's just an illustrative example, and I wanted a short absolute path that is easily recognizable to the reader. I'll fix it, though, to avoid having an example with bad security practices, though. edit: Or I would fix it, but I guess I can't edit it. Oh well.
- floren 4y agoPlan 9 does that, I'm not sure why it never made it into Unix because I always loved it. Your networking-related commands were in `/bin/ip` and you'd run e.g. `ip/ping 1.1.1.1`. If you created the dir `$home/bin/rc/my` and put scripts in it, they would have been runnable as `my/hello` etc like in your example.
- ok_dad 4y agoI use this method for aliases in my `.*rc` file so I can remember what the heck I called things. Otherwise, I forget whether I have to type something like `COMMANDNAME-log` or `log-COMMANDNAME` or some other weird combo like `print-COMMANDNAME-log`. With a comma, I type `,<tab>` and get all of my custom commands listed easily.
- Timpy 4y agoIf 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.
- xigoi 4y agoUntil you use a different machine and accidentally type your command without realizing it's not there.
- Taywee 4y agoIt can if you are executing programs that then try to execute those commands and get your commands instead.
- nerdponx 4y agoI wish it was easier to create "snapshots" of a particular set of environment variables in order to use them later as run environments. I also wish that Unix desktop environments generally made it easier to manage env vars, but that's another complaint. And don't get me started on PAM env vars...
- OJFord 4y agoJust env vars? env > "$(date +s).env-snapshot" (And use it again slightly more awkwardly as <$file | xargs -I@ echo '"@"' | tr '\n' ' ' | xargs -I@ env @ cmd or something more convenient to `cmd`.)
- prosaic-hacker 4y agoI 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.
- lkxijlewlf 4y agoI put c:\tools in my path, then put shortcuts to all my tools in there (ie: shortcut to AgentRansack named ar). Now, I pull up the run command (WND+R) type ar and agent ransack opens.
- RajT88 4y agoPermissions! Post-vista, c:\programdata\tools Set yourself a %TOOLS% environment variable.
- behnamoh 4y agoUnrelated but I heard it's possible to rename c:\ to /usr/bin or something, depending on your usage. I personally wouldn't mind renaming it to ~/<user-name> and be able to use some of my dotfiles in Windows.
- top_kekeroni_m8 4y agoIt's possible, but 90% of software will break because of this lol
- dan353hehe 4y agoI 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!
- simias 4y agoUnfortunately zsh uses the underscore prefix heavily, _<TAB> results in hundreds of possible completions.
- jamespwilliams 4y agoThis brought https://github.com/Shopify/comma https://github.com/Shopify/comma to mind
- scubbo 4y agoDo you know any of the history of why your link to `.../Shopify/...` redirects to `.../nix-community/...`? Is the latter an open-source contribution by Shopify?
- jamespwilliams 4y agoI think it was originally developed and maintained by Shopify, but was then handed off to the nix community
- behnamoh 4y agoThis is for Nix.
- hdjjhhvvhga 4y agoIn the comments, the author argues against the underscore by saying Bash/Zsh already uses it for completion. But it looks like it's a Zsh thing - at least my Bash install is pretty conservative about it.
- kelnos 4y agoNot sure what I have installed/sourced, but "_<tab>" says there are 381 possibilities for me. (This is with bash.) Also in the article itself, the author argues against any prefix char that requires using the shift key.
- avodonosov 4y agoIs it secure to have ~/bin/ it the PATH?
- paulv 4y agoThe issue is that an exploit could write a file in ~/bin/ and trick you in to executing it. But, if something malicious is writing files in your home directory, you've already lost.
- suprjami 4y agoIt's a default behaviour of at least bash. It's as secure as your home directory is.
- syoc 4y agoIf someone can write to your home directory they can also update your bashrc file and add whatever they want to PATH
- deleted 4y ago[deleted]
- aendruk 4y agoI tend to give programs longer, more descriptive names and then do the short names as shell aliases. That way there’s little risk of name collision for the original program, scripts using the canonical name remain readable, and the shorthand is free to evolve to fit varying work habits.
- quasarj 4y agoMy keyboard came with a tab key, so I don't worry about my commands having short names.
- keybored 4y agoUntil you have five commands which all use the prefix `sort-incoming-` and then three commands named `sort-incoming-hourly` and `sort-incoming-monthly` etc.
- layer8 4y agoIt would be nice to have camel-case completion in the shell, i.e. have “SIH” be completed to “SortIncomingHourly” and “SIM” to “SortIncomingMonthly”, etc. (only for upper-case characters). That way one could get more mileage out of the possible character combinations.
- andra_nl 4y agoWell, not exactly tab completion, but I have `fzf`[0] tied to my history search. That allows me to type `soriloco`, punch ctrl+r and be prompted with `some ridiculously long command` (if, of course, I've run it before). Combined with infinite history this trick has saved me a bunch of typing and even proper remembering. :P [0]: https://github.com/junegunn/fzf https://github.com/junegunn/fzf
- keybored 4y agoYes, fuzzy matching is the way to go. Tab completion isn’t good enough any more.
- TacticalCoder 4y agoI do something a bit special... Instead of naming my script foobarnator (and hence risking that another foobarnator may exist in the future and may clash with my script), I name my script foobarnatorToBeAliased.sh. Then in my list of aliases I alias foobarnator to foobarnatorToBeAliased.sh. The alias itself looks a bit weird in that to pass arguments to an aliased command you need to use a function (in Bash at least AFACIT) but it all works fine. As aliases aren't sourced when other scripts are running, I'm sure my scripts/commands ain't ever going to clash with anything. I've been doing that since years. It also works fine to add "wrappers" to existing commands: for example to add additional input sanitization catching common mistakes I'm making when calling some commands.
- ta8645 4y agoWhat has always been a blocker for me to follow your example, is the desire to use many such scripts from the command lines provided inside an $editor or $email client. There probably is a way to configure both of them to see the aliases, but it's more straightforward to just have everything in the PATH.
- nequo 4y agoYes, it seems cleaner to just put "export PATH=$HOME/bin:$PATH" in $HOME/.bashrc. That avoids collisions with /usr/bin and /usr/local/bin. (Or rather, resolves collisions in favor of your personal bin directory.)
- account42 4y agoYour PATH is inherited by child processes that you start, including scripts that expect the system version of commands that have the same name as your commands.
- rlkf 4y agoPorque no los dos? It seems that function ,foo() { printf "Fooo\n"; } ,foo actually works! (at least in my bash 5.0.17 shell)
- keybored 4y agoCool. I’m gonna start them with `å` just to be a little different.
- tveyben 4y agoThat’s be fun when you Exchange scripts with non-danes ;-))
- deleted 4y ago[deleted]
- ghostly_s 4y agoI've never once had a problem with one of my commands shadowing a system command so I think I will continue on rather than solving this non-problem, thanks.
- gumby 4y agoclever idea, but does it need such a long post to describe?
- copperx 4y agoTwo phone sized screenfuls of text is too long now? I'm genuinely interested to know whether you read longform text at all.
- gumby 4y agoI mostly read books. I don't want to pick on the author, but since you asked I will be more specific: this idea would fit in a tweet.* It's a good idea, but the long build up reminds me of recipe sites. * I just use "tweet" as a unit of measure, like "the size of two elephants". I do not advocate the use of twitter.
- infinitezest 4y agoIf you're that pressed for time, you probably could get away with just reading the title.
- deleted 4y ago[deleted]
- malkia 4y agoI almost always add "," in cmd.exe to anything I run from Windows Command Prompt? Why? Because cygwin, or mingw's `dir.exe` would be called instead of built-in dir (well, this is further complicated that I don't really use `cmd.exe` but FAR Commander), so if I want to enforce the built-in over external (same name) command I have to prepend it with "," - so I basically started typing "," in front of each of my commands...
- gregnavis 4y agoI do something similar but 1. for aliases and 2. use period. For example, when working on a Rails project I define the following alias: function .routes() { if [[ $# -eq 0 ]]; then .rails routes else .rails routes | grep $@ fi } where .rails is another alias (for running bundle exec rails ...). I can then run ".routes webhook" and see all routes containing "webhook". Last but not least, I automated the whole thing with bash-ctx (https://github.com/gregnavis/bash-ctx https://github.com/gregnavis/bash-ctx).
- jrms 4y agoI just add the .sh suffix/extension to them... And I use j- as prefix for the "tab trick"
- Maursault 4y agoThe comma is employed in bash and other shell for brace expansion.[1] I can't see how this would conflict with OP's master plan, but I have fundamental objections towards the depths of OP's laziness. Lazy is ok, but there should not be competition to see who can be laziest. At some point, things just won't compress any further, and the attempt at further streamlining efficiency beyond what is useful has a negative effect on efficiency overall. Besides, tab completion is fine as it is and doesn't need what passes for a hack these days. To be clear, contrary to what OP has claimed about not being creative enough to come up with original script names that won't conflict with the flood of new Linux commands every update (wot? LOL), this is only about the OP not being satisfied with tab completion. [1] https://superuser.com/a/184493 https://superuser.com/a/184493
- SrslyJosh 4y agoThat's a lot of words to say "I don't like this" and insult folks who put time and effort into customizations that improve their own computing experience.
- Maursault 4y ago> who put time and effort into customizations I believe you have made my point quite well once it's understood you are here referring to none other than prefixing script names with a comma. Any words wasted on anything other than the subject is a waste of words, in your comment's case, both ad hominem and straw man fallacies.
- deleted 4y ago[deleted]
- krnlpnc 4y agoI do the same thing but with prefix …
- jedberg 4y agoCommas can also be used in filenames to help you sort things instead of using underscore as a separator, useful for the same reason -- you don't have to hit shift to type it.
- luispa 4y agohaha neat.
- parentheses 4y agothe aesthetics of the comma for daily use are not good
- quickthrower2 4y agoFinally, a weird tip that is really good!
- vimsee 4y agoI started creating wrapper-scripts or simple scripts that has the commands with my prefered options or a selection menu for said command. I have started calling those scripts my<command> rsync becomes myrsync mount becomes mymount ssh becoms myssh No collision and the naming convention empathise that it is indeed used be MYself.
- pxeger1 4y agoIn Zsh, you can used named "directories" (actually it works with normal files too) with tildes for the same effect, except that they must be explicitly defined, so there's no risk of collisions. hash -d e=/bin/echo ~e hello world https://ato.pxeger.com/run?1=m724qjhjwYKlpSVpuhY3lTMSizMUdFMUUm31kzLz9FOTM_K56lIVMlJzcvIVyvOLclIUIEqhOmA6AQ https://ato.pxeger.com/run?1=m724qjhjwYKlpSVpuhY3lTMSizMUdFM...
- ZeroGravitas 4y agoSimilar to the vim <leader> key concept which many people use comma for. https://tuckerchapman.com/2018/06/16/how-to-use-the-vim-leader-key/ https://tuckerchapman.com/2018/06/16/how-to-use-the-vim-lead...
- tlarkworthy 4y agoI misadvertantly lower cased my functions names when working on .net, but it made it super easy to find my code in the stack traces. (.net idiom is capitalism the first case of a function name). Usually the cause of stack traces was my code so it was an unexpected productivity booster.
- notaclevername 4y agoI use a similar trick for text expansion. All my abbreviations start with a semicolon (;). It’s on the home row, it never occurs at the start of a word in normal typing so I never have a false positive expansion, and it’s easy to remember.
- bentinney 4y agoI am surprised to see someone else doing this, but I agree it works surprisingly well and one of my favorite tips.
- BiteCode_dev 4y agoCan't you just declare: my() { script_name="$1" script_path="$HOME/.local/bin/my/$script_name" shift $script_path "$@" } So you have your namespace ? Of course that mean you must put all script in .local/bin, not anywhere in the PATH, and some more work is needed to figure out completion. But it seems less weird than the comma. -- EDIT -- With completion: export MY_SCRIPS_DIR="$HOME/.local/bin/my" _my_completions() { if [ "${#COMP_WORDS[@]}" != "2" ]; then return fi COMPREPLY=($(compgen -W "$(echo $(find "$MY_SCRIPS_DIR" -printf '%P\n' ))")) } my() { script_name="$1" script_path="$MY_SCRIPS_DIR/$script_name" shift $script_path "$@" } complete -F _my_completions my -- EDIT 2 -- After testing both, the comma win. Kiss, more flexible.
- boffinAudio 4y agoMeh. I'd prefer to have a path not in my PATH, and then explicitly call the binary with the full path .. and then append a #comment for easy recall with CTRL-R at some point later in the future. A bit more fiddly perhaps, but future proof.
- tom_ 4y agoI have my bin folder in ~/usr/bin. The structure of ~/usr matches /usr and /usr/local, so I can build stuff into it with ./configure --prefix=$HOME/usr or similar. (You could of course do ./configure --prefix=$HOME, but then you run the risk of ending up with ~/share and ~/include and so on, something I don't want.)
- ordiel 4y agoWhy people worry so much to create "short, easy to type" (coff coff cryptic) command names, nomenclature is so important in our profession and almost everybody sucks at it, give meaningful names to things even if they are 30+ chars long, is it really that though to press 3 or 4 keys along with maybe 3 or 4 tabs?
- godshatter 4y agoI was going to post the same thing. With tab completion long names can be typed quickly anyway. Also, the keyboard is the most fundamental input device for developers... learn how to use it well. It amazes me how many people who are professional developers use copy/paste so much because they can't type well. It slows them down to a crawl. I don't particularly want to have to type 30-character names all the time without tab completion, but I'm not going to worry about an eight character command vs. a four character one. Obviously this doesn't apply if you are dyslexic or disabled in some way or something.
- uint16_t 4y agoTo mitigate issues you could just append ~/bin/ to $PATH (opposed to prepending). Then system commands have priority over your user home commands, right?