From 387ab91ec383f1bf968684337f6790189a170ab0 Mon Sep 17 00:00:00 2001 From: John Burwell Date: Thu, 19 Apr 2018 23:30:33 -0400 Subject: [PATCH] Adds Homebrew and completion support to asdf plugin * Modifies the search logic for asdf to include Homebrew when it is installed. The implementation is adapted from the pyenv plugin. Per feedback from @mcornella, asdf is either going to be in the Homebrew directory or $HOME/.asdf. Since no distributions appear to package asdf, the other locations are unncecessary. This new assumption allowed the search logic to be simplified as well. * Includes command completions for both regular and Homebrew installs. This enhancement was inspired by PR $6045. --- plugins/asdf/asdf.plugin.zsh | 37 ++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/plugins/asdf/asdf.plugin.zsh b/plugins/asdf/asdf.plugin.zsh index d563cf5f8..5054e01d5 100644 --- a/plugins/asdf/asdf.plugin.zsh +++ b/plugins/asdf/asdf.plugin.zsh @@ -1,12 +1,33 @@ -# Find where asdf should be installed. -ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}" +_homebrew-installed() { + type brew &> /dev/null +} -# Load asdf, if found. -if [ -f $ASDF_DIR/asdf.sh ]; then +FOUND_ASDF=0 +DEFAULT_ASDF_DIR="$HOME/.asdf" + +if [ -d $DEFAULT_ASDF_DIR/bin ] ; then + FOUND_ASDF=1 + ASDF_DIR="$DEFAULT_ASDF_DIR" + ASDF_COMPLETIONS_DIR="$DEFAULT_ASDF_DIR/completions" +fi + +if [ $FOUND_ASDF -eq 0 ] && _homebrew-installed ; then + ASDF_DIR="$(brew --prefix)/opt/asdf" + if [ $? -eq 0 -a -d $ASDF_DIR/bin ] ; then + FOUND_ASDF=1 + ASDF_COMPLETIONS_DIR="$ASDF_DIR/etc/bash_completion.d/asdf.bash" + fi +fi + +if [ $FOUND_ASDF -gt 0 ] ; then + export PATH=${ASDF_DIR}/bin:$PATH . $ASDF_DIR/asdf.sh + if [ -f $ASDF_COMPLETIONS_DIR/completions/asdf.bash ]; then + . $ASDF_COMPLETIONS_DIR/completions/asdf.bash + fi fi -# Load asdf completions, if found. -if [ -f $ASDF_DIR/completions/asdf.bash ]; then - . $ASDF_DIR/completions/asdf.bash -fi +unset FOUND_ASDF +unset ASDF_DIR +unset ASDF_COMPLETIONS_DIR +