Follow

hot take:
software should (almost) only have --long-options

(like, ok, -i for input is pretty obvious, but -b for "don't buffer output" needs a proper fucking name, looking at you Plan 9 coreutils, I love the OS around you, but please learn to read long options in those argparse macros)

· brutaldon · 9 · 7 · 11

if people weren't using shortopts everywhere, shell programming would be sooo much easier to learn for beginners

@grainloom I always include long ones by default. Short ones only for simple options that are commonly used.
Am I a visionary?

@ekaitz_zarraga @grainloom
Isn't that best-practice for this sort of thing? (Like, in the GNU style manual even?)

@ekaitz_zarraga @enkiv2 @grainloom
A non-standard thing I love & wish was more widespread is - vs + for flags. I almost always use this format if I'm not using something like getopts that forces the arg prefix to -

@enkiv2 @grainloom Yeah, like in chmod and stuff but chmod is quite disturbing because of the order of the arguments and the style with the numbers and so on.

tar is also one of my enemies

@grainloom I always include long ones by default. Short ones only for simple options that are commonly used.
Am I a visionary?

@grainloom my hot take: if you need the short opts to keep your shell one-liners readable to you, don't write them as shell one-liners, and instead write a bit more in python or something so you can use variable names

@bonzoesc i'm confuse, you can use variables in shells too....
(shoutout to rc for having saner variable expansion rules than sh)

@grainloom oh yeah, totally! but most of the time when i get to the point where i want to turn a one-liner into a script, i usually get to choose the language, and i like ruby more than bash

@grainloom
I don't think it would matter much if the way to look up an option wasn't grepping in a man page. The shell should be an IDE that gives you contextual help and autocompletion.

@freakazoid idk, Zsh has pretty good completion, much better even than any "proper" language I've used
manpage browsing is not that bad in acme, it is much MUCH worse if you only have a single ssh connection to a machine and no terminal multiplexing, so you gotta switch back and forth between man and the script/shell

@freakazoid afaik Fish is even better with this stuff but Zsh is good enough for my Linux system administration needs

@freakazoid @grainloom
Some tools, on some shells, will give hints about args in response to tab complete. I wish (1) this was more common, (2) it was using the same system as command-line help, and (3) it integrated with man pages so you could open up a man page without losing your place in a long under-construction shell one-liner and filter it to only the options relevant to what you're using.

@joeyh @enkiv2
I'm aware of them because some of the tools I use support them. I wish support was much more widespread, and that it also integrated with other forms of online help.

@grainloom but, thanks to history, most… many… some shortopts are POSIX compliant, while most long-opts are not

@a_breakin_glass @grainloom POSIX is supposed to be pronounced like "positive"

the suggestion came from rms

so… i agree.

@grainloom Reminds me of
> command subcommand /argument:value [path.to.file] name.ext;version

Where commands are move, copy, directory, etc. and may be shortened, unless ambiguous, to e.g. dir.

@grainloom Trying to teach my friend. That's a very good point. I will swx to long opts for him.

@grainloom That's how I wrote every shell script at every job I had :
- never rely on parameters orders, instead use long options
- avoid defaults
- print full help on any invalid invocation

I don't know if it's The Right Way, but it sure made my coworkers happy.

@grainloom Yeah, there's a few universal short options that are fine, but for 90% of CLI options, they need a long version.

Universal input options I can think of off the top of my head:

-i for input
-o for output
-a for all
-s for silent
-v for verbose

Unless I'm missing any, these are the only acceptable shortcodes that don't need a long version.

@SoniEx2 @KitsuneAlicia you need version info a lot less though, i don't think it needs a short option, --version is fine

@KitsuneAlicia @grainloom
Do -i and -o make sense to include? We should probably read from stdin & write to stdout in the normal case & expect users to pipe or redirect for any case where a bare filename would seem strange, right?

@SoniEx2 oh. so that's what the quotation marks are for.....

@grainloom

Counter-take, if folks wrote good completion scripts for their apps then it wouldn't matter.

@grainloom #OCaml programs (Arg module) don't have the distinction: all options start with single dash. And generally they are way easier to parse there, than in C with getopts.

@grainloom it'd be a pain if I had to spell out

ssh --proxy-jump host1 host2

every time, instead of

ssh -J host1 host2

@Wolf480pl what about abstracting it a bit? if you need shorthands, just wrap the executable?
yknow, the same way how modules abstract over / combine other modules

@Wolf480pl but imho there should be a builtin way for executables to complete their arguments, which would make this quicker

@grainloom To be fair, today I came across a PowerShell command with the option -VirtualMachineMigrationAuthenticationType which... is great for script readability, but would be a nightmare to type on a console. So that is one reason I appreciate that most bash commands have short options, though long options are also a must. People should have, uh, options 😅

@kazooboy that is going a bit too far, something like -auth-type would suffice for that
but better integrated auto-completion could help with both, i've heard others before suggest executables should be able to give hints to shells about autocompletion, and I think that's something worth checking out.

@grainloom That would be pretty cool! Would give some of the best of both worlds.

VirtualMachineMigrationAuthenticationTypeFactoryFactory
Sign in to participate in the conversation
Cybrespace

Cybrespace is an instance of Mastodon, a social network based on open web protocols and free, open-source software. It is decentralized like e-mail.