-
Notifications
You must be signed in to change notification settings - Fork 791
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
fix!: rework POSIX entrypoint for greater shell support #1480
Conversation
d34ebc1
to
d19f903
Compare
That structure predates me, so not sure of motivation. Perhaps @Stratus3D can shed some light on it. EDIT: |
This is a monumental change and can potentially break a lot of stuff. I am leaning towards merging other PRs first, releasing them, then merging this after the next release so that people can play with it on |
Right. It seems if we are targeting actual EDIT: However, that doesn't solve the partial support in a single file. So perhaps it is best to extract the |
@Stratus3D hasn't replied to #1397 (comment) But I believe we're on the same page about treating these files as |
That sounds good 👍
I don't really see an issue if the zsh-specific syntax doesn't cause a problem when the file is parsed by POSIX shells. We need to have this zsh specific syntax, or at least some variant of it so
Just to be a bit more clear, it was shfmt having the issues parsing the file - shellcheck works fine. But I definitely see your point about turning off formatting for a particular file. I think there is another way I can express the same thing while keeping the formatter happy. |
Okay so I made the ZSH change, and now shfmt is tripping up again. Here is the change: diff --git a/asdf.sh b/asdf.sh
index d7dd4c7..5e66fc4 100644
--- a/asdf.sh
+++ b/asdf.sh
@@ -29,11 +29,10 @@ if [ -z "$ASDF_DIR" ]; then
fi
unset -v _asdf_old_dir
elif [ -n "$ZSH_VERSION" ]; then
- # Use '%x' to expand to path of current file. It must be prefixed
- # with '(%):-', so it expands in non-prompt-string contexts.
+ # Use '%x' to expand to path of current file. It must be used with
+ # '-P', since depends on prompt expansion.
- # shellcheck disable=SC2296
- ASDF_DIR=${(%):-%x}
+ print -P -v ASDF_DIR '%x'
ASDF_DIR=${ASDF_DIR%/*}
elif [ -n "$KSH_VERSION" ] && [ -z "$PATHSEP" ]; then
# Only the original KornShell (kornshell.com) has a '.sh.file' variable with the path With It looks impossible to make the |
Hey can this get another look? v0.11.2 was just released a week or so ago, so now is an opportune time to merge as mentioned here. |
12e543e
to
1d34bf4
Compare
The errors from I believe this is just revealing that we should have separate Just because each of these shells share a lineage with some common syntax or features is a bad reason to keep the code in one place and turn off our automatic validation on such a crucial aspect of our code. So my suggestion now would be either:
I'm thinking out loud here. We could just turn off |
I suppose you could argue that the
So nothing (except formatting) is lost when turning |
I also want to mention, that before my changes, there was no clear separation between shells, functionality was broken for both KSH and POSIX Shells, and ShellCheck wasn't being ran on Since my changes only fix things, would it be OK to just merge these changes, and if you really wish to separate things into different files (which I would strongly disagree with), to do it in some later PR? |
7d2a30f
to
a8166d4
Compare
Yes, you're right. Sorry, I lost context of the past conversation as there was a gap in time in which I was able to review and contribute to this conversation.
Yes, let's just merge this and we can discuss the other changes in future Issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work, thanks very much @hyperupcall 🙏
We will merge this and let people test it with asdf update --head
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a really great set of changes. Thanks for your hard work on this @hyperupcall and @jthegedus !
I think I've wondered the same thing. I seem to remember thinking all the logic in it could either be moved into |
Summary
Earlier it was discovered that
shfmt
andshellcheck
were not running properly on some entrypoint files (asdf.sh
andlib/asdf.sh
. As #1397 states, they were identified as Bash when they should have been identified as POSIX shell.This PR updates both shfmt and shellcheck to parse the aforementioned files as
POSIX
with one slight nuance:shfmt
sometimes spuriously prints errors when encountering ZSH-specific syntax (./asdf.sh:34:16: parameter expansion requires a literal
). Because of this,shfmt
no longer runs onasdf.sh
.I'm not sure if there is still confusion as to whether these files should be treated as (Bash and ZSH) or POSIX, but because we know (from #1138) that users are using shells such as
mksh
(and at least for me, I know I wantasdf
to continue to work if i jump intodash
orash
), I'm treating these files as POSIX shell files. And POSIX compliance isn't too much work since we're only dealing with two files.Moving attention back to the changes itself, I make the following fixes:
dash
would error when parsingasdf.sh
ASDF_BIN
andASDF_USER_SHIMS
are no longer capitalized (they aren't environment variables), and they are now properly unset beforelib/asdf.sh
is sourcedcurrent_script_path="$0"
(this doesn't work)$0
usually holds the path or name the binary of the currently executing shell (ex./usr/bin/bash
,dash
)_under="$_"
$_
rarely actually works in practice (writing something as innocuous as: somevar
beforesource .../asdf.sh
breaks this functionality). In my opinion, this flaky behavior is not worth implementing, and I added a workaround for the original Korn shell anyways.(maybe I'll make a separate PR for this)PATH
is no longer modified (i consider it bad practice)Other non-essential improvements:
{BASH,ZSH,KSH}_VERSION
)_asdf_
and properlyunset
them on errorsasdf: Error
so the source of the error is clear (related to No version manager name reported in CLI output, consider adding it #1467)I tested this with
dash
,bash
,zsh
,ksh
, andmksh
.TODOdash
,sh
, and all POSIX-shellsOther Information
I'm thinking that
lib/asdf.sh
should be removed. I'm not sure what useful purpose it serves, as its contents can easily be written inasdf.sh
(same withlib/asdf.fish
, etc.). Thoughts?