Skip to content

Instantly share code, notes, and snippets.

@jpstroop
Last active December 26, 2021 15:58
Show Gist options
  • Save jpstroop/9d3fcb8f8f03f91f46b10aa361da6b82 to your computer and use it in GitHub Desktop.
Save jpstroop/9d3fcb8f8f03f91f46b10aa361da6b82 to your computer and use it in GitHub Desktop.
asdf which extension - adds an option to specify a version as the third arg to the which subcommand and get a path the binary
# (Paste into your bash .profile or whatever you use)
#
# $ asdf which python
# /Users/jstroop/.asdf/installs/python/3.8.5/bin/python # version in .tool-versions
# $ asdf which python 3.7.6
# /Users/jstroop/.asdf/installs/python/3.7.6/bin/python # version from 3rd arg
#
# NOTE: Python < 3.11-dev does not compile on Apple silicon.
# See: https://bugs.python.org/issue43878.
# Use Rosetta if necessary.
#
## For Homebrew on macOS
. $(brew --prefix asdf)/libexec/asdf.sh
. $(brew --prefix)/etc/bash_completion.d/asdf.bash
ASDF_LANGS=("python" "ruby") # may need expansion for other langs.
function asdf() {
if [[ "$1" == "which" && "${ASDF_LANGS[@]}" =~ "${2}" && "$3" != "" ]]; then
shift 1
where=$(asdf where $1 $2)
if [[ "$where" == "Version not installed" ]]; then
command echo $where
else
command echo $where/bin/$1
fi
else
command asdf "$@"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment