39 ms·
Start all of your commands with a comma (2009)
- sevg 8mo agoThis is one of those ideas that is so simple and elegant that it makes you think “why did I never think of doing this?!” Neat trick! I don’t think I’ll namespace everything this way, because there’s some aliases and commands I run so often that the comma would get annoying, but for other less frequently used helper scripts then this will be perfect!
- pjerem 8mo agoMaybe then try ending your commands with a comma so that you don’t break first-char autocomplete !
- stavros 8mo agoBut that's the killer feature for me! I always forget the little commands I've written over the years, whereas a leading comma will easily let me list them.
- bonzini 8mo agoI do something similar with build trees, naming them +build, +cross-arm etc. This convention was suggested by the GNU Arch version control system years ago (maybe 20??), but it's really useful for the same tab completion reason and I have kept it for almost two decades, even when I switched to git.
- amszmidt 8mo agoIt was suggested by Tom Lord (RIP), who used it heavily long before he wrote GNU Arch. File names or directories starting with a comma where considered “junk”, and ones with a plus sign I think where considered “precious”.
- dadandang 8mo ago,Start all of your commands with a comma
- zdc1 8mo agoShould be titled Prefix your script names with a comma. Current title is a little clickbait-y through its ambiguity.
- albert_e 8mo agoAgree. I thought the title meant I should type ,ls instead of ls.
- JamesTRexx 8mo ago,sudo make me a sammich Like so?
- guilherme-puida 8mo ago(2009)
- HelloUsername 8mo agoPrevious discussions: 2024: https://news.ycombinator.com/item?id=40769362 https://news.ycombinator.com/item?id=40769362 2022: https://news.ycombinator.com/item?id=31846902 https://news.ycombinator.com/item?id=31846902 2020: https://news.ycombinator.com/item?id=22778988 https://news.ycombinator.com/item?id=22778988
- bronlund 8mo agoThis is just brilliant. Thanks.
- falloutx 8mo agoFinally a post that is relevant to what I have been looking for quite some time. Also, kudos to keeping it so concise and to the point, thats some prime writing.
- luplex 8mo agosimilarly, I start all my underscorends with an underscore
- mathfailure 8mo agoI didn't like the idea. I prefer the alternative approach: _I_ decide the order of dirs in the PATH env. If I introduce an executable with a name, that overrides a system one - I probably do that intentionally. If I introduce an alias (like `grep='grep --binary-files=without-match --ignore-case --color=auto`) that matches the name of a system binary - I probably do that intentionally. And if I EVER need to call grep without my alias - I just prefix it with a backslash: \grep will search with case sensitivity and no color and will scan binaries.
- karolist 8mo agoInteresting, though I never had enough custom scripts to justify this, I prefer oh-my-zsh plugin style short aliases instead, i.e. https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git
- 1vuio0pswjnm7 8mo agoI use a different prefix character, e.g. "[", but I have been doing this for years I started using a prefix because I like very short script names that are easy to type I prefer giving scripts numbers instead of names Something like "[number" I use prefixes and suffixes to group related scripts together, e.g., scripts that run other scripts I have an executable directory like ~/bin but it's not called bin. It contains 100s of short scripts
- feelamee 8mo agodo you publish dotfiles and scripts anywhere? I'm interested to see them
- mathfailure 8mo ago> I prefer giving scripts numbers instead of names > Something like "[number" > It contains 100s of short scripts So you call scripts like [1 [2 [3 [4 ... and remember what each one of them does? If yes - that's nuts, I'd visit a doctor.
- 1vuio0pswjnm7 8mo ago"..., I'd visit a doctor" But I'm not you
- 1vuio0pswjnm7 8mo agoThank you
- renewiltord 8mo agoThis is utterly unhinged. I freaking love it. It reminds me of the old joke about prisoners and numbers for jokes (Stanislaw Lem has a similar concept in a book): A prisoner, new to a particular cell block, was surprised to discover that his fellow inmates passed much of their day by calling out numbers, after which they would laugh heartily for a few moments. Every few minutes an inmate would call out a number and everyone would laugh, and then, after a few moments of silence, someone else would call out a number, and once again laughter. The inmate asked one of the other inmates whom he'd come to know to explain this strange behavior to him. "It's simple", came the reply. "We know all of our jokes by heart, and there's really no reason to tell them at lenght. Instead, we simply call them out by number." Though this was strange to him, the new inmate thought he'd join in on the fun. After a few weeks listening to the jokes, he took some initiative and called out "number 27!". But nobody laughed. This seemed very strange to him, since he'd heard others call out that same number, with everyone laughing afterwards. After waiting and waiting, with still no laughter, he finally asked: "why is it that when others call out that joke you laugh, and when I called it, nobody laughed?". The reply promptly came: "You told it wrong".
- ndsipa_pomu 8mo agoI appreciate the idea, but the comma just looks horrible to me as part of a filename. I can imagine someone unfamiliar with the naming scheme to get confused. I'd prefer to use underscore (when writing BASH scripts, I name all my local variables starting with underscore), but a simple two or three letter prefix would also work. I don't like the idea of a punctuation prefix as punctuation usually has a specific meaning somewhere and including it as the first character in a filename looks wrong. (e.g. Comma is typically used as a list separator and it's a bit of cognitive dissonance to see it not used in that context)
- eterps 8mo agoI use my_ as a prefix.
- JamesTRexx 8mo agoWhenever I see "my" as a prefix, it feels like such a childish "my first Sony" thing. I hate official sites using that.
- SoftTalker 8mo agoThis was actually the same feeling I had when I tried to learn perl. I just had a visceral dislike for "my" as the keyword to declare a local variable.
- ndsipa_pomu 8mo agoI used to use "do" as a prefix e.g. "doBackup" Nowadays, I tend to skip using a personal prefix and just try to name commands with a suitable verb in front (e.g. "backupMySQL") and ensure that there's no name collisions.
- k3vinw 8mo agoThat’s a more meaningful prefix than “,” at the expense of a couple more key strokes. I consider that to still be a win in the book of tab completions. I would replace underscore with “-“ or “.”
- gugod 8mo agoI tried a variant or this idea so many years ago after I leaned git and rearranged some of my personal tools as subcommands (like git) of a single executable named "dude," It went weird pretty quickly...
- eMPee584 8mo ago.. examples?
- renewiltord 8mo agodude, whois my.car
- deleted 8mo ago[deleted]
- caeruleus 8mo agoPrefixing commands solves the namespace problem and discoverability (at least partly). I use a slightly more sophisticated method, which helps me remember which custom utilities are available and how to use them: sd [1], a light wrapper written for zsh that, in addition to namespaces, provides autocompletion, custom help texts + some other QoL enhancements. Can definitely recommend if you're looking for something a bit more fancy. [1] https://github.com/ianthehenry/sd https://github.com/ianthehenry/sd
- ljouhet 8mo agoMost of my aliases contain `--` for the same reason, `git--progress`, `grep--rIn`, `nvidia--kill`, `ollama--restart`, `rsync--cp`, `pdf--nup`... Easy autocomplete, I know there won't be any collision, and which command is mine.
- finghin 8mo agoGreat hack!
- mathfailure 8mo agoKinda makes no sense to me: so you don't use '--' as a prefix, you use it in the middle of an alias, so you first have to autocomplete, say, 'gi' not to 'git' but to 'git--progress'. What does that alias do? Doesn't it call git with some args? If so - why not just alias it to git?
- jph 8mo agoClever hack! <3 I also do namespacing yet in a different way. I create a home directory "x" for executables that I want to manage as files, and don't want on PATH or as alias. To run foo: ~/x/foo For example I have GNU date as ~/x/date so it's independent of the system BSD date.
- mromanuk 8mo agoIt’s clever, but is not aesthetic. A comma feels unnatural in the fs.
- mystifyingpoi 8mo agoIt doesn't have to be a literal file, it can be an alias.
- lupire 8mo agoThat doesn't make it "feel" less "unnatural".
- layer8 8mo agoSo did the dot in dotfiles originally. You’ll get used to it if you want to.
- tomcam 8mo agoEvery tool and shell that lay in arm's reach treated the comma as a perfectly normal and unobjectionable character in a filename. WTF. After 40 years maybe I should have figured that one out.
- pm215 8mo agoIt's not a completely non special character: for instance in bash it's special inside braces in the syntax where "/{,usr/}bin" expands to "/bin /usr/bin". But the need to start that syntax with the open brace will remind you about the need to escape a literal comma there if you ever want one.
- mike-the-mikado 8mo agoUntil someone forces you to use a file system that cannot tolerate commas...
- XCSme 8mo agoWhat about using the filename in arrays in bash/sh?
- impoppy 8mo agoWhy so many people use ~/bin/? What’s wrong with ~/.local/bin?
- zhouzhao 8mo agoNothing. I also use `~/.local/bin/`
- dark-star 8mo ago~/bin/ preceeds the XDG Base Directory Specification. ~/.local was only invented around 2003 and gained widespread usage maybe 15 years or so ago... People used ~/bin already in the 90s ;-)
- 1313ed01 8mo agoRandom things are installed in ~/.local/bin. In ~/bin I have only what I put there.
- mixmastamyk 8mo agoPython and rust (for example) package managers install user wide tools there.
- pmarreck 8mo agoThe latter is XDG. ~/bin predates it. And of course you can use both.
- kps 8mo agoPersonally I use ~/opt//bin where ~/opt is a ‘one stop shop’ containing various things, including a symlink to ~/local and directories or symlinks for things that don't play well with others (e.g. cargo, go), and an ~/opt/prefer/bin that goes at the start of PATH containing symlinks to resolve naming conflicts. (Anything that modifies standard behaviour is not in PATH, but instead a shell function present only in interactive shells, so as not to break scripts.) Unix lore: Early unix had two-letter names for most common names to make them easy to type on crappy terminals, but no one* letter command names because the easier were reserved for personal use.
- laughing_snyder 8mo ago> Like many Unix users, I long ago created a ~/bin/ directory in my home directory `.local/bin` seems to be much more common in my experience for this use case. And for good reason.
- zhouzhao 8mo agoUnclutter your $HOME!
- Levitating 8mo ago~/bin is actually created per default on OpenSUSE (though it's removal has been discussed several times).
- yunohn 8mo agoI read this blog a few years ago, and implemented it soon after with a refresh of my rc files and shortcuts. Gamechanger - has helped me every single day since. It’s easy to remember, autocompletes easily, and adds a little flair of personalization.
- tezza 8mo agoThis is a really good practical step if you worry about name collisions quick, easy and consistent. entirely voluntary. Bravo
- vitorsr 8mo agoNice although I think the ASCII comma feels wrong as part of a filename even if for purely aesthetic reasons. If we want to stay within (lowercase) alphabetic Latin characters I think prefixing with the least common letters or bigrams that start a word (x, q, y, z, j) is best. `y' for instance only autocompletes to `yes' and `ypdomainname' on my path. Choosing a unique bigram is actually quite easy and a fun exercise. And we can always use uppercase Latin letters since commands very rarely use never mind start with those.
- diydsp 8mo agoIts some what natural to german spkrs who use a special set of double quotes to start a quote in print.
- deleted 8mo ago[deleted]
- skerit 8mo agoI would have never thought of that. Funny that a comma can be used like that. Off-topic: What the hell is that font on this website? And why does the "a" look like that?
- groue 8mo agoGentium is a very beautiful font: https://software.sil.org/gentium/ https://software.sil.org/gentium/
- feelamee 8mo agocan someone explain security consideration of placing scripts into $HOME? Some time ago I moved all my scripts to /usr/local/bin, because I feel that this is better from security perspective.
- Galanwe 8mo agoThere are no security implications, on the contrary. It is objectively cleaner to keep your user scripts in your home, that way they are only in _your_ PATH, whereas putting them in /usr/[local/]bin implicitly adds them to every [service] user on the machine, which I can see creating obscure undesired effets. Not even mentioning the potential issues with packages that could override your scripts at install, unexpected shadowing of service binaries, setuid security implications, etc.
- layer8 8mo agoSomeone with access to your home dir can also set your $PATH and aliases to anything they want, so I don’t see any extra security considerations here.
- alzee 8mo agoUsing commas in filenames feels kind of weird to me, but I do use a comma as the initiator for my Bash key sequences. For example: ,, expands to $ ,h expands to --help ,v expands to --version ,s prefixes sudo You put keyseqs in ~/.inputc, set a keyseq-timeout, and it just works.
- pmarreck 8mo agowould an alias just work in this use-case?
- listeria 8mo agoGlobal aliases are a zsh feature and not avaliable in bash. So if you want: openssl ,v to expand to... openssl --version readline seems like the way to go. Then again most of the examples OP gave are usually available as short options, and aliasing ,s to sudo is certainly possible. So the only one which makes sense to me is ,,=$. But it's probably not worth the trouble to my muscle memory.
- alzee 8mo ago> most of the examples OP gave are usually available as short options Yes, but a lot of commands behave differently for -h and --help. > aliasing ,s to sudo is certainly possible Sure, but my ,s key sequence doesn’t just expand to sudo. It actually moves the cursor to the start of the current line, prefixes the command with sudo, and then moves the cursor to the end of the line. The idea is when you type a command which requires root privileges but forget to use sudo, you can just hit ctrl+p ,s to fetch the previous command and prefix it with sudo. This is what it looks like in ~/.inputrc: ",s":"^Asudo ^E"
- pmarreck 8mo agoalso. did you mean .inputrc ?
- alzee 8mo agoYes, I meant ~/.inputrc .
- Tade0 8mo agoAs a non-native English speaker I just name them in my native language or using British English spelling. I have a command named "decolour", which strips (most) ANSI escape codes. Clear as day what it does, almost nobody uses this spelling when naming commands that later land as part of a distribution.
- temporallobe 8mo agoI don’t think this is a terrible idea, though stylistically it bothers me. I suppose you could simply have a prefix command router that would essentially do the same thing. I also started using “task” recently and it’s been a game changer for my CLI life.
- mogoh 8mo agoWhat is task?
- alex-moon 8mo agoIt is like make but designed specifically for the way non-C(++) users - people like me for example adding scripts like "make run" and "make build" to my node/python/PHP/etc repos - use it. It is great! I still don't use it literally just because make is already installed on any *nix system I encounter day to day.
- renewiltord 8mo agoI used task previously and now use mise for it since I have a mise version file usually anyway.
- temporallobe 8mo agoInteresting, I have never compared make with task but I suppose there’s some overlap. My favorite feature is that it’s cross-platform. I do use it for performing complex builds (like chaining several environment setup and docker compose commands, etc.). Of course you could do this with shell scripts, but this adds a layer of abstraction.
- deleted 8mo ago[deleted]
- nickelpro 8mo agoProperly manage PATH for the context you're in and this is a non-issue. This is the solution used by most programming environments these days, you don't carry around the entire npm or PyPI ecosystem all the time, only when you activate it. Then again, I don't really believe in performing complex operations manually and directly from a shell, so I don't really understand the use-case for having many small utilities in PATH to begin with.
- dcchuck 8mo agoI prefer all my custom commands as 1 letter. On my most frequently used machine/dev env this means - e for vim m for mise n for pnpm c for Claude x for codex
- dddw 8mo agod for deploy to production
- Ylpertnodi 8mo agof for friday
- maleldil 8mo agor for uv run j for just I use fish abbreviations for this, as they expand to the full command in the shell history.
- jkercher 8mo agoTangentially related. Don't ever put "." in your PATH. I used to do this to avoid typing the "./" to execute something in my current directory. BAD IDEA. It can turn a typo into a fork bomb. I took down a production server trying to save typing two characters.
- Kiboneu 8mo agolol. What a beautiful footgun — for such a tiny optimization.
- lanyard-textile 8mo agoElaborate?? "." has been at the end of my PATH for like 20 years.
- ahepp 8mo agoJust to save the trouble of writing './'?
- lanyard-textile 8mo agoYes??? :) I'm not the crazy one here! That's a whole two characters on the same side of the keyboard...
- oneeyedpigeon 8mo agoHow often do you find yourself running executables from the current directory? Is this a daily thing?
- piekvorst 8mo agoFor my workflow, yes I don’t think it’s a severe security vulnerability. The same thing can happen with $home/bin.
- 8mo ago
- Dove 8mo agoIn many contexts in which I am trying to deconflict namespaces, I use my initials. I hadn't thought about it in this particular context, though now that I do, it seems fortunate that I am ced rather than sed.
- michaelcampbell 8mo agoGlad it worked for OP, but I've never once in 30+ years of this had a conflict that did something I didn't want. ~/bin/ is early in my PATH, and for a good reason. Things I put in there I want to take precedence, so I use this to purposely override provided bins. (Though I can only think of one time I wanted to do that, too.)
- macintux 8mo agoThis has been a popular topic nearly every time the post makes the HN front page. * https://news.ycombinator.com/item?id=40769362 https://news.ycombinator.com/item?id=40769362 (2024, 169 comments) * https://news.ycombinator.com/item?id=31846902 https://news.ycombinator.com/item?id=31846902 (2022, 123 comments) * https://news.ycombinator.com/item?id=22778988 https://news.ycombinator.com/item?id=22778988 (2020, 90 comments)
- FergusArgyll 8mo agohn is at it's best when discussing bash shenanigans
- z0ltan 8mo ago[dead]
- elhosots 8mo agoI think its a fairly good idea - but for myself, i had already mapped csh’s default history character (!) to a comma (,) for the same reason - no shift key to invoke.
- mixmastamyk 8mo agocsh? I used the enhanced tcsh on Irix in the 90s.
- matheus-rr 8mo agoThis is one of those "obvious in hindsight" tricks. The comma prefix gives you a namespace that's guaranteed to never collide with system binaries, shell builtins, or anything from a package manager. I do something similar with my personal scripts — prefix them with a short namespace. The real win isn't just avoiding collisions though, it's tab completion. Type the prefix and tab, and you immediately see all your custom stuff without wading through hundreds of system commands. The 2009 date on this is wild. Some of these simple unix conventions age better than most frameworks.
- pkulak 8mo agoThere’s this program on nix that lets you type a comma, then any application name that exists anywhere in the Nix repos. It then downloads that app and runs it once, without “installing” it. Sometimes I find myself running something dozens of times this way before I realize it should probably be in my config.
- xyzzy_plugh 8mo agohttps://github.com/nix-community/comma https://github.com/nix-community/comma
- Arcuru 8mo agoI'm not sure I'll ever understand why they replaced their working ~50 line shell script with a Rust program that just shells out to the same nix-* commands. I appreciate that there are some safety benefits, but that program is just not complex enough to benefit.
- rafram 8mo agoBecause it's "a proper language" [1]. Not to mention webscale! It does seem to do some more complex stuff now that would've been annoying, but not impossible, to write as a shell script. [1]: https://github.com/nix-community/comma/pull/19 https://github.com/nix-community/comma/pull/19
- aidenn0 8mo agoShell is already memory safe, so there's not even "we replaced C" to lean on.
- pkulak 8mo agoMaybe it was fun?
- synergy20 8mo agoinstead of using ~/bin I use ~/installed/bin, sometimes I need build a command from source then install it, which might have share/ man/ etc so I can avoid installing them under the home dir.
- mixmastamyk 8mo ago~/.local/ could work for this, and as another user mentioned easier to separate the back up.
- nh2 8mo agoWorth pointing out that with Nix/NixOS this problem doesn't exist. The problem in other distros is that if you prefix PATH so that it contains your executable "foo", and then run a program that invokes "foo" from PATH and expects it to do something else, the program breaks. With Nix, this problem does not exist because all installed programs invoke all other programs not via PATH but via full absolute paths starting with /nix/store/HASH...
- ablob 8mo agoSo if I want to use grep in a small script, do I have to write: /nix/store/grep-hash -flags files | /nix/store/head-hash instead of: "grep -flags files | head"?
- xaduha 8mo ago[user@nixos:~]$ which grep /run/current-system/sw/bin/grep [user@nixos:~]$ ls -l /run/current-system/sw/bin/grep lrwxrwxrwx 1 root root 65 Jan 1 1970 /run/current-system/sw/bin/grep -> /nix/store/737jwbhw8ji13x9s88z3wpp8pxaqla92-gnugrep-3.12/bin/grep Basically, it is still in your environment, so I don't see how he can claim that this problem doesn't exist in Nix, unless you use flakes like a proper Nix afficionado.
- aidenn0 8mo agoYes, the original comment that this problem doesn't exist in Nix is wrong for a typical user environment. It does contain the issue a bit though: I'm running isync in a systemd service, yet the program "mbsync" is not in my path. I have several services installed, yet their programs aren't in my path. My e-mail client shells out to "file" for mime-type verification, yet "file" is not in my path. Run "compgen -c |wc -l" to get a list of commands; its over 7000 on my Ubuntu system and right around 2000 on my NixOS system. As an aside, the packages that put the most executables in my path are probably going to be in the path for most NixOS installs (231 just for coreutils+util-linux): 27 /nix/store/csxa6mi2mpjl9vqxbv2j0bha6sz6nbjw-cups-2.4.14 31 /nix/store/334afxah19b3hr6ll93pfxlcyhhh2vws-pipewire-1.4.9 31 /nix/store/h2jsb5i4yfblr2f3ac2c7zpmlmj7zjym-perl-5.40.0 33 /nix/store/914x32c982bs3i1998yxvkg9svm3ycr5-shadow-4.18.0 33 /nix/store/a6s3hzj3b2z6rsyfkjyxwn265iyfl2gn-mtools-4.0.49 33 /nix/store/jky7jszaci5n7g426wf6nsg5dmik9nfw-kbd-2.9.0 37 /nix/store/2v1l6mqz0d7mfpp4ksw2048v3g0a1a19-hplip-3.25.2 45 /nix/store/90wlc37ljr6rpy2lan46bp0gq19vbgl5-iptables-1.8.11 48 /nix/store/1byhxs7b28grh8s15jc2dvs2zg36swjb-lvm2-2.03.35-bin 61 /nix/store/9xwxjkrwxjsvc5gs1l0syr4wbfvvvvcn-bluez-5.84 64 /nix/store/zf8qy81dsw1vqwgh9p9n2h40s1k0g2l1-systemd-258.2 72 /nix/store/1igrj9w84w7s3r80l3nkxcqwd84sw9mz-qemu-10.1.2 106 /nix/store/v4q3154vdc83fxsal9syg9yppshdljyk-coreutils-full-9.8 125 /nix/store/3c6r8gh8zrqw8xmncmlj9vivz9rz6r30-util-linux-2.41.2-bin
- polyrand 8mo agoI do this, and it's a huge quality of life improvement. No so much because of shadowing existing binaries, but for better command auto-complete. For example: I have a bunch of tmux utilities and all start with `,t` which is not a polluted command-name prefix compared to just `t`. But I'm now facing the problem that LLM agents don't like this, and when I instruct them to run certain tools, they remove the leading comma. It's normally fixed with one extra sentence in the prompt, but still inconvenient.
- ahepp 8mo agoOne could set an env var to their local bin dir which is otherwise not in the path, like L=/home/ahepp/.local/bin, and then do $L/mycommand. Doesn't meet the OP's requirement of no shift key. Or prefix files in the local bin dir with a couple letters from your username, like /home/ahepp/.local/bin/ah-mycommand
- moritzwarhier 8mo agoWhy not just start every alias or script with ë or something?
- ezfe 8mo agoComma is easier to type and less visually distracting
- moritzwarhier 8mo agomakes sense, article mentions not wanting composite keys. There goes my sarcasm. However, I'd advocate for an ë key then.
- tasuki 8mo agoI never did this and never once experienced a name conflict.
- grimgrin 8mo agoin vim i am very fond of two mapping prefixes: <space> and , they're both so easy to reach for
- bilbo-b-baggins 8mo agoLove this thread reminding me that most experts in computers are unhinged lunatics doing convoluted and tortured things on a daily basis that they consider perfectly normal and even convenient.
- jmux 8mo agoyes this is totally cursed but I kinda love the idea
- jchook 8mo agoA lot of vim users use comma as the leader key so this is probably natural for a lot of folks. Also seems convenient to be able to type ,<tab> to autocomplete over your custom commands, in case you forgot the name you assigned them.
- ekipan 8mo agoI actually have the below clashes function in my bashrc to detect overloaded names, and a few compgen aliases for sorted formatted command lists. Clashes takes a few seconds to chew through the 3000ish commands on my Steam Deck. I also discovered the comma thing myself, and use it for `xdg-open <web-search-url>` aliases, i.e. `,aw xdg` searches archwiki for "xdg", since the SteamOS on this thing doesn't have manpages. alias words='iftty xargs' # join by spaces alias c='compgen -c | sort -u | words' # eg: c | grep ^k | chop # ... a for aliases, f for functions etc ... alias man='g !archman' # https://man.archlinux.org alias ,aw='g !aw' # https://wiki.archlinux.org alias ,mdn='g !mdn' # https://developer.mozilla.org alias ,nix='g !nixpkgs' # https://search.nixos.org # ... a dozen others ... g() { local IFS=+; xdg-open "https://ddg.gg/?q=$*"; } iftty() { if [ -t 1 ]; then "$@"; else cat; fi; } chop() { # [TABS] [STARTCOL] [CUTOPTS..] # eg. ls ~/.co* | chop set -- "${1:-2}" "${2:-1}" "${@:3}" cut -c "$2"-$(($2+8*$1-2)) "${@:3}" | column #| less } clashes() { # [CMDS..] # print overloads eg: clashes $(c) (($#)) || set -- $(compgen -A alias -A function) local ty cmd; for cmd; do ty=($(type -at "$cmd")) ((${#ty[@]}>1)) && echo -n "$cmd "; done; echo }
- dvershinin 8mo agoI do something similar but with a project prefix. I maintain a lot of packaging scripts and settled on prefixing them by project - gps-build, gps-deploy, gps-sync etc. Tab completion does the rest. The real issue isn't collisions though, it's discoverability. Six months later you forget half of what you wrote. The prefix at least lets you type gps-<tab> and see everything at a glance.
- da-x 8mo agoAlternative, you can check whether there are duplicates under $PATH resolutions - binaries that can come from more than one place in $PATH. #!/usr/bin/env -S cargo eval -- // cargo-deps: derive-error="0", is_executable="0" // vi: ft=rust use derive_error::Error; use is_executable::IsExecutable; use std::collections::{BTreeMap, HashSet, btree_map}; use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; #[derive(Debug, Error)] pub enum Error { VarEnv(std::env::VarError), Io(std::io::Error), } fn main() -> Result<(), Error> { let mut paths_seen = HashSet::new(); let mut path_fileid_seen = HashSet::new(); let mut exes_seen = BTreeMap::new(); for path in std::env::var("PATH")?.split(":") { let path = PathBuf::from(path); if !path.is_dir() { continue; } if !path_fileid_seen.insert(path.metadata()?.ino()) { continue; } if paths_seen.insert(path.clone()) { match std::fs::read_dir(&path) { Err(_) => { eprintln!("error listing {:?}", path); } Ok(readdir) => { for entry in readdir { let entry = entry?; if entry.path().is_executable() { let mut item = match exes_seen.entry( String::from(entry.path().file_name() .unwrap().to_string_lossy().as_ref())) { btree_map::Entry::Vacant(v) => v.insert(vec![]), btree_map::Entry::Occupied(o) => o.into_mut(), }; item.push(path.clone()); } } } } } } for (exe, paths) in exes_seen.into_iter() { if paths.len() == 2 { let mut strs = vec![]; for path in paths.iter() { strs.push(path.to_str().unwrap()); } if strs.as_slice() == ["/usr/bin", "/usr/sbin"] { continue; } } if paths.len() > 1 { println!("{}: ", exe); for path in paths { println!(" {}", path.to_str().unwrap()); } println!(""); } } Ok(()) }
- AceyMan 8mo agoThe comma has an unusual but super handy usage in PowerShell. When it precedes a variable of any array (list) type, the code it's the input to handles it as an array object, defending against the usual tendency to "unpack" the array and read in the elements that compose it.
- casey2 8mo ago~/bin/cmd $HOME/bin/cmd c=$HOME/bin/ ; ${c}cmd # if you really are dead set on obfuscating your scripts. Rather than the limited "magic of tab completion" I prefer the simple, yet general ls $HOME/bin