Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricter POSIX sh compliance #440

Open
mcandre opened this issue May 9, 2020 · 3 comments
Open

Stricter POSIX sh compliance #440

mcandre opened this issue May 9, 2020 · 3 comments

Comments

@mcandre
Copy link

mcandre commented May 9, 2020

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
@havenwood
Copy link
Collaborator

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!

@mcandre
Copy link
Author

mcandre commented May 12, 2020

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?

@FranklinYu
Copy link
Contributor

From ReadMe:

Anti-Features

  • Does not hook cd.

I guess it’s because aliasing cd has already been in many user’s .bashrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants