2012-08-08 04:36:09 +02:00
|
|
|
#!/usr/bin/env bash
|
2012-12-30 22:10:23 +01:00
|
|
|
#
|
2012-12-30 22:25:52 +01:00
|
|
|
# Summary: Uninstall a specific Ruby version
|
|
|
|
#
|
2013-01-30 00:22:56 +01:00
|
|
|
# Usage: rbenv uninstall [-f|--force] <version>
|
2012-12-30 22:10:23 +01:00
|
|
|
#
|
|
|
|
# -f Attempt to remove the specified version without prompting
|
|
|
|
# for confirmation. If the version does not exist, do not
|
|
|
|
# display an error message.
|
|
|
|
#
|
|
|
|
# See `rbenv versions` for a complete list of installed versions.
|
|
|
|
#
|
2012-08-08 04:36:09 +02:00
|
|
|
set -e
|
|
|
|
|
|
|
|
# Provide rbenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
2015-12-03 21:09:48 +01:00
|
|
|
echo --force
|
2012-08-15 06:08:31 +02:00
|
|
|
exec rbenv versions --bare
|
2012-08-08 04:36:09 +02:00
|
|
|
fi
|
|
|
|
|
2014-11-17 15:44:50 +01:00
|
|
|
usage() {
|
2015-06-02 03:41:42 +02:00
|
|
|
rbenv-help uninstall 2>/dev/null
|
2014-11-17 15:44:50 +01:00
|
|
|
[ -z "$1" ] || exit "$1"
|
|
|
|
}
|
|
|
|
|
2014-11-27 05:40:09 +01:00
|
|
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|
|
|
usage 0
|
2012-08-08 04:36:09 +02:00
|
|
|
fi
|
|
|
|
|
2012-08-15 22:08:53 +02:00
|
|
|
unset FORCE
|
2013-01-30 00:22:56 +01:00
|
|
|
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
|
2012-08-15 22:08:53 +02:00
|
|
|
FORCE=true
|
2012-08-15 06:08:31 +02:00
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2014-11-27 04:51:11 +01:00
|
|
|
[ "$#" -eq 1 ] || usage 1 >&2
|
2014-11-27 04:45:52 +01:00
|
|
|
|
2012-08-08 04:36:09 +02:00
|
|
|
DEFINITION="$1"
|
|
|
|
case "$DEFINITION" in
|
|
|
|
"" | -* )
|
2014-11-27 04:51:11 +01:00
|
|
|
usage 1 >&2
|
2012-08-08 04:36:09 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-06-04 11:59:58 +02:00
|
|
|
declare -a before_hooks after_hooks
|
|
|
|
|
|
|
|
before_uninstall() {
|
|
|
|
local hook="$1"
|
|
|
|
before_hooks["${#before_hooks[@]}"]="$hook"
|
|
|
|
}
|
|
|
|
|
|
|
|
after_uninstall() {
|
|
|
|
local hook="$1"
|
|
|
|
after_hooks["${#after_hooks[@]}"]="$hook"
|
|
|
|
}
|
|
|
|
|
2013-12-30 14:45:16 +01:00
|
|
|
OLDIFS="$IFS"
|
|
|
|
IFS=$'\n' scripts=(`rbenv-hooks uninstall`)
|
|
|
|
IFS="$OLDIFS"
|
|
|
|
for script in "${scripts[@]}"; do source "$script"; done
|
2013-06-04 11:59:58 +02:00
|
|
|
|
|
|
|
|
2012-08-08 04:36:09 +02:00
|
|
|
VERSION_NAME="${DEFINITION##*/}"
|
|
|
|
PREFIX="${RBENV_ROOT}/versions/${VERSION_NAME}"
|
|
|
|
|
2012-08-15 06:08:31 +02:00
|
|
|
if [ -z "$FORCE" ]; then
|
|
|
|
if [ ! -d "$PREFIX" ]; then
|
|
|
|
echo "rbenv: version \`$VERSION_NAME' not installed" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-05-01 15:45:23 +02:00
|
|
|
if [ ! -t 0 ]; then
|
|
|
|
echo "rbenv: must use \`--force' in non-interactive mode" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-11-26 07:05:35 +01:00
|
|
|
read -p "rbenv: remove $PREFIX? [yN] "
|
2012-08-15 06:08:31 +02:00
|
|
|
case "$REPLY" in
|
|
|
|
y* | Y* ) ;;
|
|
|
|
* ) exit 1 ;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2013-06-04 11:59:58 +02:00
|
|
|
for hook in "${before_hooks[@]}"; do eval "$hook"; done
|
|
|
|
|
2012-08-15 06:08:31 +02:00
|
|
|
if [ -d "$PREFIX" ]; then
|
|
|
|
rm -rf "$PREFIX"
|
2014-01-04 14:43:42 +01:00
|
|
|
rbenv-rehash
|
2012-08-08 04:36:09 +02:00
|
|
|
fi
|
2013-06-04 11:59:58 +02:00
|
|
|
|
|
|
|
for hook in "${after_hooks[@]}"; do eval "$hook"; done
|