Stricter POSIX sh compliance
mcandre opened this issue · 3 comments
This would allow more users to benefit from chruby!
- POSIX sh users
- ksh users
- dash users
- ash users
- posh users
- yash users
- oil shell users
It seems there are two potential blockers for your proposal.
First, neither POSIX nor these shells have preexec functions. POSIX doesn't specify a pre-function trap, which is needed for auto.sh switching to work.
Second, features like local
would have to be dropped to find a common subset of behavior that's undefined by POSIX but still portable.
As the Oil author writes, POSIX doesn't define enough common ground so shells have gone beyond it and diverged.
For bigger programs, limiting yourself to POSIX is not just inconvenient, it's also an ill-defined and virtually untestable concept...
Local variables are essential for writing maintainable shell scripts, but POSIX doesn't mention them.
This issue isn't theoretical — bash and dash differ in practice, but POSIX doesn't specify which is correct. In other words, POSIX is incomplete and out of date. (However, I've discovered that shells are highly conformant with respect to things the standard does specify.)
In other words, POSIX is incomplete and out of date. (However, I've discovered that shells are highly conformant with respect to things the standard does specify.)
There's an mksh branch of chruby that's portable and works other than mksh not supporting preexec functions. I don't think any of the shells you list do, which would mean no auto switching until they implement a prexec function feature. A shell like Oil or mksh might do that—but dash and friends likely never will. I saw preexec functions mentioned as a possible mksh function, but they haven't implemented it as far as I know.
Would you think it's worth targeting portability for any of these shells without support for auto switching?
P.S. It was fun looking into Oil shell. Thanks for mentioning it!
POSIX doesn't specify a pre-function trap, which is needed for auto.sh switching to work.
I think you might be right about that. I was under the impression that chruby and friends were simply aliasing cd
. Is that not sufficient for implementing good version switchers?
From ReadMe:
Anti-Features
- Does not hook
cd
.
I guess it’s because aliasing cd
has already been in many user’s .bashrc
.