bin/asdf-fzf-uninstall
#!/usr/bin/env bash
#
# Remove one or more versions of specified language
# e.g. `asdf-remove rust` # => fzf multimode, tab to mark, enter to remove
# if no plugin is supplied (e.g. `asdf-remove<CR>`), fzf will list them for you
#
# 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
}
# Remove one or more versions of specified language
# e.g. `vmi rust` # => fzf multimode, tab to mark, enter to remove
# if no plugin is supplied (e.g. `vmi<CR>`), fzf will list them for you
asdf-remove() {
local lang=${1}
if [[ ! $lang ]]; then
lang=$(asdf plugin-list | fzf)
fi
if [[ $lang ]]; then
local versions
versions=$(asdf list "$lang" | fzf -m)
if [[ $versions ]]; then
for version in $versions
do
asdf uninstall "$lang" "$version"
done
fi
fi
}
if has asdf; then
asdf-remove "$@"
else
fail "Can't find asdf in $PATH"
fi