bin/asdf-fzf-install
#!/usr/bin/env bash
#
# Install one or more versions of specified language
# e.g. `asdf-install rust` # => fzf multimode, tab to mark, enter to install
# if no plugin is supplied (e.g. `asdf-install<CR>`), fzf will list them for you
# Mnemonic [V]ersion [M]anager [I]nstall
#
# Source: https://github.com/junegunn/fzf/wiki/examples
set -o pipefail
if [[ -n "$DEBUG" ]]; then
set -x
fi
function fail() {
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
}
function has() {
# Check if a command is in $PATH
which "$@" > /dev/null 2>&1
}
# Install one or more versions of specified language
# e.g. `vmi rust` # => fzf multimode, tab to mark, enter to install
# if no plugin is supplied (e.g. `vmi<CR>`), fzf will list them for you
# Mnemonic [V]ersion [M]anager [I]nstall
asdf-install() {
local lang=${1}
if [[ ! $lang ]]; then
lang=$(asdf plugin-list | fzf)
fi
if [[ $lang ]]; then
local versions
versions=$(asdf list-all "$lang" | fzf --tac --no-sort --multi)
if [[ $versions ]]; then
for version in $versions
do
asdf install "$lang" "$version"
done
fi
fi
}
if has asdf; then
asdf-install "$@"
else
fail "Can't find asdf in $PATH"
fi