asdf/lib/commands/which.sh

34 lines
1.2 KiB
Bash
Raw Normal View History

which_command() {
local command=$1 plugins_path not_found plugin_name full_version location
2018-10-20 20:47:13 -07:00
plugins_path=$(get_plugin_path)
if ls "$plugins_path" &> /dev/null; then
for plugin_path in "$plugins_path"/* ; do
plugin_name=$(basename "$plugin_path")
full_version=$(get_preset_version_for "$plugin_name")
2018-10-20 20:56:28 -07:00
# shellcheck disable=SC2162
2018-10-20 20:47:13 -07:00
IFS=' ' read -a versions <<< "$full_version"
for version in "${versions[@]}"; do
if [ -f "${plugin_path}/bin/exec-path" ]; then
cmd=$(basename "$executable_path")
2018-10-20 20:56:28 -07:00
install_path=$(find_install_path "$plugin_name" "$version")
2018-10-20 20:47:13 -07:00
executable_path="$("${plugin_path}/bin/exec-path" "$install_path" "$cmd" "$executable_path")"
fi
full_executable_path=$(get_executable_path "$plugin_name" "$version" "$executable_path")
location=$(find -L "$full_executable_path" -maxdepth 4 -name "$command" -type f -perm -u+x | sed -e 's|//|/|g')
if [ -n "$location" ]; then
2018-10-20 20:56:28 -07:00
echo "$location"
2018-10-20 20:47:13 -07:00
not_found=0
break 2
2018-10-20 20:47:13 -07:00
else
not_found=1
fi
done
done
fi
if [ $not_found -eq 1 ]; then
echo "No executable binary found for $command"
exit 1
fi
2018-10-20 20:47:13 -07:00
exit 0
}