2011-08-12 11:33:45 +02:00
|
|
|
#!/usr/bin/env bash
|
2012-12-29 12:06:20 -06:00
|
|
|
# Summary: List all available rbenv commands
|
|
|
|
|
# Usage: rbenv commands [--sh|--no-sh]
|
2024-04-29 14:20:47 +02:00
|
|
|
#
|
|
|
|
|
# List names of all rbenv commands, including 3rd-party ones found in the
|
|
|
|
|
# PATH or in rbenv plugins. With `--sh`, list only shell commands.
|
|
|
|
|
#
|
|
|
|
|
# This functionality is mainly meant for scripting. To see usage help for
|
|
|
|
|
# rbenv, run `rbenv help`.
|
2012-12-29 12:06:20 -06:00
|
|
|
|
2011-08-12 11:33:45 +02:00
|
|
|
set -e
|
2011-09-12 10:11:59 -05:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-08-03 22:20:01 -05:00
|
|
|
|
2011-09-13 12:48:49 -05:00
|
|
|
# Provide rbenv completions
|
|
|
|
|
if [ "$1" = "--complete" ]; then
|
2011-09-13 13:12:04 -05:00
|
|
|
echo --sh
|
|
|
|
|
echo --no-sh
|
2011-09-13 12:48:49 -05:00
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
2025-01-08 14:29:19 +01:00
|
|
|
exclude_shell=
|
|
|
|
|
command_prefix="rbenv-"
|
|
|
|
|
|
2011-08-23 11:34:03 -05:00
|
|
|
if [ "$1" = "--sh" ]; then
|
2025-01-08 14:29:19 +01:00
|
|
|
command_prefix="rbenv-sh-"
|
2011-08-23 11:34:03 -05:00
|
|
|
shift
|
2011-09-13 12:48:49 -05:00
|
|
|
elif [ "$1" = "--no-sh" ]; then
|
2025-01-08 14:29:19 +01:00
|
|
|
exclude_shell=1
|
2011-09-06 22:07:05 -05:00
|
|
|
shift
|
|
|
|
|
fi
|
|
|
|
|
|
2011-08-03 22:20:01 -05:00
|
|
|
shopt -s nullglob
|
|
|
|
|
|
2025-01-08 14:29:19 +01:00
|
|
|
{
|
|
|
|
|
PATH_remain="$PATH"
|
|
|
|
|
# traverse PATH to find "rbenv-" prefixed commands
|
|
|
|
|
while true; do
|
|
|
|
|
path="${PATH_remain%%:*}"
|
|
|
|
|
if [ -n "$path" ]; then
|
|
|
|
|
for rbenv_command in "${path}/${command_prefix}"*; do
|
|
|
|
|
rbenv_command="${rbenv_command##*rbenv-}"
|
|
|
|
|
if [[ -z $exclude_shell || $rbenv_command != sh-* ]]; then
|
|
|
|
|
echo "${rbenv_command##sh-}"
|
2011-08-23 11:34:03 -05:00
|
|
|
fi
|
2025-01-08 14:29:19 +01:00
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
[[ $PATH_remain == *:* ]] || break
|
|
|
|
|
PATH_remain="${PATH_remain#*:}"
|
2011-08-03 22:20:01 -05:00
|
|
|
done
|
|
|
|
|
} | sort | uniq
|