asdf.sh: support mksh

The mksh shell (and perhaps others too) will not be able to determine a
sourced script's path by looking at either `${BASH_SOURCE[0]}` or `$0`.

By capturing the value of `$_` as the very first thing the script does,
`asdf.sh` can use that as the input for `dirname` in order to determine
a value to use for `$ASDF_DIR`.

I have tested this change with mksh to confirm that it works, and have
also tested it with both bash and zsh to verify that neither of those
stop working.

This resolves the only compatibility issue I've ran into with asdf,
caused by mksh sourcing a script. All subsequent asdf usage involves an
asdf executable doing the sourcing, so it's bash to bash at that point.
This commit is contained in:
fallwith 2019-02-20 16:42:45 -08:00
parent 76410eca46
commit f8d843926a

View File

@ -1,6 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ "${BASH_SOURCE[0]}" != "" ]; then _under="$_"
if [[ "$_under" == *".sh" ]]; then
current_script_path="$_under"
elif [ "${BASH_SOURCE[0]}" != "" ]; then
current_script_path="${BASH_SOURCE[0]}" current_script_path="${BASH_SOURCE[0]}"
else else
current_script_path="$0" current_script_path="$0"