Re:Start all of your commands with a comma (2009)
by Taywee on Thursday June 23, 2022 @04:01PM
(#31854448)
Clever trick. Too bad there's no good way to namespace commands. It would be interesting if you could have, for instance:
[ Parent
| on HN ]
Re:Start all of your commands with a comma (2009)
by floren on Thursday June 23, 2022 @05:11PM
(#31855206)
Plan 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.
Re:Start all of your commands with a comma (2009)
by yellowapple on Thursday June 23, 2022 @06:53PM
(#31856095)
Plan 9 also more or less does away with the concept of $PATH in the first place; just union-mount (with `bind`) whatever you want onto `/bin` and call it a day. Yet another thing that would've been great for Unix-likes to pull in (I think some Linuxen can technically do it, but with some limitations).
Re:Start all of your commands with a comma (2009)
by lawl on Friday June 24, 2022 @09:38AM
(#31861604)
All linuxen should be able to do that with overlayfs, I think.
Re:Start all of your commands with a comma (2009)
by keyle on Thursday June 23, 2022 @08:07PM
(#31856564)
no matter which kind of twisted idea someone comes up with related to terminals, there is always a guy who chimes in with "in Plan 9 you can do that...". It makes me smile every time. :)
Re:Start all of your commands with a comma (2009)
by theblazehen on Friday June 24, 2022 @03:17AM
(#31858641)
I've tested it and it works on Linux (bash and zsh), at least for your custom commands
Re:Start all of your commands with a comma (2009)
by lou1306 on Thursday June 23, 2022 @05:22PM
(#31855323)
Ahem, technically there is one way (don't know if it is "good", though):
$ export $MY = /tmp/my
$ $MY/hello
hello
Re:Start all of your commands with a comma (2009)
by gpderetta on Thursday June 23, 2022 @08:24PM
(#31856642)
What about:
my hello
I.e. only my needs to be in the global namespace and all other commands are resolved by my itself.
Re:Start all of your commands with a comma (2009)
by akho on Saturday June 25, 2022 @04:25PM
(#31878439)
You’d need to set up tab completion for the `my` command. This is more effort than just naming everything `my-foo` — or `,foo`.
Re:Start all of your commands with a comma (2009)
by gpderetta on Saturday June 25, 2022 @06:59PM
(#31879427)
Good point.
Re:Start all of your commands with a comma (2009)
by layer8 on Thursday June 23, 2022 @05:29PM
(#31855382)
You could (ab)use home directories for that. I.e. place your hello into /home/my, and then you can invoke it as ~my/hello. You even get namespace completion for free after the `~`.
Re:Start all of your commands with a comma (2009)
by Beltalowda on Thursday June 23, 2022 @07:42PM
(#31856427)
In zsh you can do "hash -d my=/path/to/my" and then you can use "~my/hello" from anywhere, and it doesn't need to be in /home.
Re:Start all of your commands with a comma (2009)
by account42 on Monday June 27, 2022 @04:35AM
(#31891980)
> and it doesn't need to be in /home.
Neither do home directories.
Re:Start all of your commands with a comma (2009)
by eurasiantiger on Thursday June 23, 2022 @04:06PM
(#31854504)
Just add another comma. Of course, this needs some deeper magic to work :)
,my,hello
Re:Start all of your commands with a comma (2009)
by woodruffw on Thursday June 23, 2022 @04:28PM
(#31854737)
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'
Re:Start all of your commands with a comma (2009)
by Someone on Friday June 24, 2022 @04:03AM
(#31858930)
I think shells should support that, allowing you to do
$ my hello
It would mean tools such as git, microk8s and aws wouldn’t have to implement that “look up first argument, check whether it’s a command I know, and if so, run it” on their own, and would have slightly simpler auto complete configs.It also could mean launching fewer processes (for the case where ‘my’ is a script or executable that looks up the location of ‘hello’ and launches it)
Re:Start all of your commands with a comma (2009)
by ianthehenry on Thursday June 23, 2022 @07:29PM
(#31856356)
zsh can do this if you set the PATH_DIRS option, but if I remember right it doesn't autocomplete deeply nested directories, just one level.
I made a little tool that dispatches hierarchical commands in a slightly nicer way, with intelligent autocomplete with command descriptions: https://github.com/ianthehenry/sd
Re:Start all of your commands with a comma (2009)
by jwilk on Thursday June 23, 2022 @04:58PM
(#31855077)
> mkdir -p /tmp/bin/my
This is not a secure way of using /tmp.
Re:Start all of your commands with a comma (2009)
by Taywee on Thursday June 23, 2022 @06:22PM
(#31855820)
Sure, 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.