Update `asdf.sh` to explain that `$_`, `${BASH_SOURCE[0]}`, and `$0`
are used by Korn, Bash, and Zsh (and others) to obtain the path to the
script, and what those special variables mean.
Add a "shell" command similar to the existing "global" and "local"
commands, which sets the version in an environment variable instead of
writing it to a file. This was inspired by the similar functionality in
rbenv.
It works by adding a wrapper function for the asdf command. It forwards
to a "sh-shell" command that returns the exports as shell code which is
then evaled by the wrapper. This is a little gross, but we need to run
the code in the shell context in order to set variables.
Resolves#378
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.
Users of `zsh` can define hook functions that execute when
the current directory changes. If a user has their `zsh`
configured with a hook function that writes to stdout, the
`asdf` setup script will capture that output in addition to
the output of `pwd`, which causes a misconfiguration of the
`PATH` environment variable.
By redirecting the output, if any, of the `cd` command to
`/dev/null`, this ensures that the path to `bin` in `asdf`
is captured correctly regardless of `zsh` configuration.
Referred a couple other version managers. The advantage is not having to
maintain the scripts for other shells (bash comes by default everywhere
I've seen).