Browse Source

First commit

pull/4/head
Gildas Cuisinier 13 years ago
commit
f55a9c80b1
  1. 0
      README.md
  2. 1
      bin/jenv
  3. 14
      completions/jenv.bash
  4. 19
      completions/jenv.zsh
  5. 80
      libexec/jenv
  6. 26
      libexec/jenv-add
  7. 38
      libexec/jenv-commands
  8. 15
      libexec/jenv-completions
  9. 30
      libexec/jenv-exec
  10. 21
      libexec/jenv-global
  11. 88
      libexec/jenv-help
  12. 44
      libexec/jenv-hooks
  13. 98
      libexec/jenv-init
  14. 24
      libexec/jenv-local
  15. 29
      libexec/jenv-prefix
  16. 149
      libexec/jenv-rehash
  17. 2
      libexec/jenv-root
  18. 32
      libexec/jenv-sh-shell
  19. 17
      libexec/jenv-shims
  20. 5
      libexec/jenv-version
  21. 24
      libexec/jenv-version-file
  22. 24
      libexec/jenv-version-file-read
  23. 17
      libexec/jenv-version-file-write
  24. 22
      libexec/jenv-version-name
  25. 9
      libexec/jenv-version-origin
  26. 27
      libexec/jenv-versions
  27. 35
      libexec/jenv-whence
  28. 83
      libexec/jenv-which
  29. 2
      plugins/maven/etc/jenv.d/rehash/maven.bash

1
bin/jenv

@ -0,0 +1 @@ @@ -0,0 +1 @@
../libexec/jenv

14
completions/jenv.bash

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
_jenv() {
COMPREPLY=()
local word="${COMP_WORDS[COMP_CWORD]}"
if [ "$COMP_CWORD" -eq 1 ]; then
COMPREPLY=( $(compgen -W "$(jenv commands)" -- "$word") )
else
local command="${COMP_WORDS[1]}"
local completions="$(jenv completions "$command")"
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
fi
}
complete -F _jenv jenv

19
completions/jenv.zsh

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
if [[ ! -o interactive ]]; then
return
fi
compctl -K _jenv jenv
_jenv() {
local word words completions
read -cA words
word="${words[2]}"
if [ "${#words}" -eq 2 ]; then
completions="$(jenv commands)"
else
completions="$(jenv completions "${word}")"
fi
reply=("${(ps:\n:)completions}")
}

80
libexec/jenv

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
}
if [ -z "${JENV_ROOT}" ]; then
JENV_ROOT="${HOME}/.jenv"
else
JENV_ROOT="${JENV_ROOT%/}"
fi
export JENV_ROOT
if [ -z "${JENV_DIR}" ]; then
JENV_DIR="$(pwd)"
else
cd "$JENV_DIR" 2>/dev/null || {
echo "jenv: cannot change working directory to \`$JENV_DIR'"
exit 1
} >&2
JENV_DIR="$(pwd)"
cd "$OLDPWD"
fi
export JENV_DIR
shopt -s nullglob
bin_path="$(abs_dirname "$0")"
for plugin_bin in "${JENV_ROOT}/plugins/"*/bin; do
bin_path="${bin_path}:${plugin_bin}"
done
export PATH="${bin_path}:${PATH}"
hook_path="${JENV_HOOK_PATH}"
for plugin_hook in "${JENV_ROOT}/plugins/"*/etc/jenv.d; do
hook_path="${hook_path}:${plugin_hook}"
done
export JENV_HOOK_PATH=$hook_path
shopt -u nullglob
command="$1"
case "$command" in
"" | "-h" | "--help" )
echo -e "jenv 0.1.0\n$(jenv-help)" >&2
;;
* )
command_path="$(command -v "jenv-$command" || true)"
if [ -z "$command_path" ]; then
echo "jenv: no such command \`$command'" >&2
exit 1
fi
shift 1
exec "$command_path" "$@"
;;
esac

26
libexec/jenv-add

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo --unset
echo system
exec jenv-versions --bare
fi
JENV_VERSION="$1"
JENV_JAVAPATH="$2"
JENV_VERSION_FILE=".jenv-version"
echo $JENV_VERSION
echo $JENV_JAVAPATH
if [ -f "$JENV_JAVAPATH/bin/java" ];
then
ln -s "$JENV_JAVAPATH" "${JENV_ROOT}/versions/$JENV_VERSION"
else
echo "$JENV_JAVAPATH is not a valid path to java installation"
fi

38
libexec/jenv-commands

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo --sh
echo --no-sh
exit
fi
if [ "$1" = "--sh" ]; then
sh=1
shift
elif [ "$1" = "--no-sh" ]; then
nosh=1
shift
fi
shopt -s nullglob
{ for path in ${PATH//:/$'\n'}; do
for command in "${path}/jenv-"*; do
command="${command##*jenv-}"
if [ -n "$sh" ]; then
if [ ${command:0:3} = "sh-" ]; then
echo ${command##sh-}
fi
elif [ -n "$nosh" ]; then
if [ ${command:0:3} != "sh-" ]; then
echo ${command##sh-}
fi
else
echo ${command##sh-}
fi
done
done
} | sort | uniq

15
libexec/jenv-completions

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
COMMAND="$1"
if [ -z "$COMMAND" ]; then
echo "usage: jenv completions COMMAND [arg1 arg2...]" >&2
exit 1
fi
COMMAND_PATH="$(command -v "jenv-$COMMAND" || command -v "jenv-sh-$COMMAND")"
if grep -i "^# provide jenv completions" "$COMMAND_PATH" >/dev/null; then
shift
exec "$COMMAND_PATH" --complete "$@"
fi

30
libexec/jenv-exec

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
exec jenv shims --short
fi
export JAVA_HOME="${JENV_ROOT}/versions/$(jenv-version-name)"
JENV_COMMAND="$1"
if [ -z "$JENV_COMMAND" ]; then
echo "usage: jenv exec COMMAND [arg1 arg2...]" >&2
exit 1
fi
JENV_COMMAND_PATH="$(jenv-which "$JENV_COMMAND")"
JENV_BIN_PATH="${JENV_COMMAND_PATH%/*}"
#for script in $(jenv-hooks exec); do
# source "$script"
#done
shift 1
export PATH="${JENV_BIN_PATH}:${PATH}"
echo $PATH
exec -a "$JENV_COMMAND" "$JENV_COMMAND_PATH" "$@"

21
libexec/jenv-global

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo system
exec jenv-versions --bare
fi
JENV_VERSION="$1"
JENV_VERSION_FILE="${JENV_ROOT}/version"
if [ -n "$JENV_VERSION" ]; then
jenv-version-file-write "$JENV_VERSION_FILE" "$JENV_VERSION"
else
jenv-version-file-read "$JENV_VERSION_FILE" ||
jenv-version-file-read "${JENV_ROOT}/global" ||
jenv-version-file-read "${JENV_ROOT}/default" ||
echo system
fi

88
libexec/jenv-help

@ -0,0 +1,88 @@ @@ -0,0 +1,88 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
print_set_version() {
echo "<version> should be a string matching a Ruby version known by jenv."
local versions="$(jenv-versions --bare)"
if [ -z "$versions" ]; then
echo "There are currently no Ruby versions installed for jenv."
else
echo "The currently installed Ruby versions are:"
echo "$versions" | sed 's/^/ /'
fi
echo
echo "The special version string 'system' will use your default system Ruby."
}
case "$1" in
"") echo "usage: jenv <command> [<args>]
Some useful jenv commands are:
commands List all jenv commands
rehash Rehash jenv shims (run this after installing binaries)
global Set or show the global Ruby version
local Set or show the local directory-specific Ruby version
shell Set or show the shell-specific Ruby version
version Show the current Ruby version
versions List all Ruby versions known by jenv
which Show the full path for the given Ruby command
whence List all Ruby versions with the given command
See 'jenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/jenv#readme"
;;
global) echo "usage: jenv global <version>
Sets the global Ruby version. You can override the global version at
any time by setting a directory-specific version with \`jenv local'
or by setting the JENV_VERSION environment variable.
$(print_set_version)"
;;
local) echo "usage: jenv local <version>
jenv local --unset
Sets the local directory-specific Ruby version by writing the version
name to a file named '.jenv-version'.
When you run a Ruby command, jenv will look for an '.jenv-version'
file in the current directory and each parent directory. If no such
file is found in the tree, jenv will use the global Ruby version
specified with \`jenv global', or the version specified in the
JENV_VERSION environment variable.
$(print_set_version)"
;;
shell) echo "usage: jenv shell <version>
jenv shell --unset
Sets a shell-specific Ruby version by setting the 'JENV_VERSION'
environment variable in your shell. This version overrides both
project-specific versions and the global version.
$(print_set_version)"
;;
which) echo "usage: jenv which <command>
Displays the full path to the binary that jenv will execute when you
run the given command."
;;
whence) echo "usage: jenv whence <command>
Lists all Ruby versions with the given command installed."
;;
*)
command_path="$(command -v "jenv-$1" || true)"
if [ -n "$command_path" ]; then
echo "Sorry, the \`$1' command isn't documented yet."
echo
echo "You can view the command's source here:"
echo "$command_path"
echo
else
echo "jenv: no such command \`$1'"
fi
esac

44
libexec/jenv-hooks

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo exec
echo rehash
echo which
exit
fi
JENV_COMMAND="$1"
if [ -z "$JENV_COMMAND" ]; then
echo "usage: jenv hooks COMMAND" >&2
exit 1
fi
resolve_link() {
$(type -p greadlink readlink | head -1) $1
}
realpath() {
local cwd="$(pwd)"
local base="$(basename $1)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
echo "$(pwd)/$base"
cd "$cwd"
}
shopt -s nullglob
for path in ${JENV_HOOK_PATH//:/$'\n'}; do
for script in $path/"$JENV_COMMAND"/*.bash; do
echo $(realpath $script)
done
done
shopt -u nullglob

98
libexec/jenv-init

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
print=""
if [ "$1" = "-" ]; then
print=1
shift
fi
no_rehash=""
if [ "$1" = "--no-rehash" ]; then
no_rehash=1
shift
fi
shell="$1"
if [ -z "$shell" ]; then
shell="$(basename "$SHELL")"
fi
resolve_link() {
$(type -p greadlink readlink | head -1) $1
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
}
root="$(abs_dirname "$0")/.."
if [ -z "$print" ]; then
case "$shell" in
bash )
profile='~/.bash_profile'
;;
zsh )
profile='~/.zshrc'
;;
ksh )
profile='~/.profile'
;;
* )
profile='your profile'
;;
esac
{ echo "# Load jenv automatically by adding"
echo "# the following to ${profile}:"
echo
echo 'eval "$(jenv init -)"'
echo
} >&2
exit 1
fi
mkdir -p "${JENV_ROOT}/"{shims,versions}
echo 'export PATH="'${JENV_ROOT}'/shims:${PATH}"'
case "$shell" in
bash | zsh )
echo "source \"$root/completions/jenv.${shell}\""
;;
esac
if [ -z "$no_rehash" ]; then
echo 'jenv rehash 2>/dev/null'
fi
commands=(`jenv commands --sh`)
IFS="|"
cat <<EOS
jenv() {
command="\$1"
if [ "\$#" -gt 0 ]; then
shift
fi
case "\$command" in
${commands[*]})
eval \`jenv "sh-\$command" "\$@"\`;;
*)
command jenv "\$command" "\$@";;
esac
}
EOS

24
libexec/jenv-local

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo --unset
echo system
exec jenv-versions --bare
fi
JENV_VERSION="$1"
JENV_VERSION_FILE=".jenv-version"
if [ "$JENV_VERSION" = "--unset" ]; then
rm -f "$JENV_VERSION_FILE"
elif [ -n "$JENV_VERSION" ]; then
jenv-version-file-write "$JENV_VERSION_FILE" "$JENV_VERSION"
else
jenv-version-file-read "$JENV_VERSION_FILE" ||
{ echo "jenv: no local version configured for this directory"
exit 1
} >&2
fi

29
libexec/jenv-prefix

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo system
exec jenv-versions --bare
fi
if [ -n "$1" ]; then
export JENV_VERSION="$1"
elif [ -z "$JENV_VERSION" ]; then
JENV_VERSION="$(jenv-version-name)"
fi
if [ "$JENV_VERSION" = "system" ]; then
RUBY_PATH="$(jenv-which ruby)"
echo "${RUBY_PATH%/*}"
exit
fi
JENV_PREFIX_PATH="${JENV_ROOT}/versions/${JENV_VERSION}"
if [ ! -d "$JENV_PREFIX_PATH" ]; then
echo "jenv: version \`${JENV_VERSION}' not installed" >&2
exit 1
fi
echo "$JENV_PREFIX_PATH"

149
libexec/jenv-rehash

@ -0,0 +1,149 @@ @@ -0,0 +1,149 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
SHIM_PATH="${JENV_ROOT}/shims"
PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.jenv-shim"
# Create the shims directory if it doesn't already exist.
mkdir -p "$SHIM_PATH"
# Ensure only one instance of jenv-rehash is running at a time by
# setting the shell's `noclobber` option and attempting to write to
# the prototype shim file. If the file already exists, print a warning
# to stderr and exit with a non-zero status.
set -o noclobber
{ echo > "$PROTOTYPE_SHIM_PATH"
} 2>/dev/null ||
{ echo "jenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
exit 1
} >&2
set +o noclobber
# If we were able to obtain a lock, register a trap to clean up the
# prototype shim when the process exits.
trap remove_prototype_shim EXIT
remove_prototype_shim() {
rm -f "$PROTOTYPE_SHIM_PATH"
}
# The prototype shim file is a script that re-execs itself, passing
# its filename and any arguments to `jenv exec`. This file is
# hard-linked for every binary and then removed. The linking technique
# is fast, uses less disk space than unique files, and also serves as
# a locking mechanism.
create_prototype_shim() {
cat > "$PROTOTYPE_SHIM_PATH" <<SH
#!/usr/bin/env bash
set -e
export JENV_ROOT="$JENV_ROOT"
exec jenv exec "\${0##*/}" "\$@"
SH
chmod +x "$PROTOTYPE_SHIM_PATH"
}
# The basename of each argument passed to `make_shims` will be
# registered for installation as a shim. In this way, plugins may call
# `make_shims` with a glob to register many shims at once.
make_shims() {
local shims="$@"
for file in $shims; do
local shim="${file##*/}"
register_shim "$shim"
done
}
# Create an empty array for the list of registered shims.
registered_shims=()
# We will keep track of shims registered for installation with the
# global `reigstered_shims` array and with a global variable for each
# shim. The array will let us iterate over all registered shims. The
# global variables will let us quickly check whether a shim with the
# given name has been registered or not.
register_shim() {
local shim="$@"
local var="$(shim_variable_name "$shim")"
if [ -z "${!var}" ]; then
registered_shims[${#registered_shims[*]}]="$shim"
eval "${var}=1"
fi
}
# To compute the global variable name for a given shim we must first
# escape any non-alphanumeric characters. If the shim name is
# alphanumeric (including a hyphen or underscore) we can take a
# shorter path. Otherwise, we must iterate over each character and
# escape the non-alphanumeric ones using `printf`.
shim_variable_name() {
local shim="$1"
local result="_shim_"
if [[ ! "$shim" =~ [^[:alnum:]_-] ]]; then
shim="${shim//_/_5f}"
shim="${shim//-/_2d}"
result+="$shim"
else
local length="${#shim}"
local char i
for ((i=0; i<length; i++)); do
char="${shim:$i:1}"
if [[ "$char" =~ [[:alnum:]] ]]; then
result+="$char"
else
result+="$(printf "_%02x" \'"$char")"
fi
done
fi
echo "$result"
}
# To install all the registered shims, we iterate over the
# `registered_shims` array and create a link if one does not already
# exist.
install_registered_shims() {
for shim in "${registered_shims[@]}"; do
[ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
done
}
# Once the registered shims have been installed, we make a second pass
# over the contents of the shims directory. Any file that is present
# in the directory but has not been registered as a shim should be
# removed.
remove_stale_shims() {
local var
for shim in *; do
var="$(shim_variable_name "$shim")"
[ -z "${!var}" ] && rm -f "$shim"
done
}
# Change to the shims directory.
cd "$SHIM_PATH"
# Create the prototype shim, then register shims for all known binaries.
create_prototype_shim
shopt -s nullglob
#make_shims ../versions/*/bin/*
# Restore the previous working directory.
cd "$OLDPWD"
# Allow plugins to register shims.
for script in $(jenv-hooks rehash); do
source "$script"
done
# Change back to the shims directory to install the registered shims
# and remove stale shims.
cd "$SHIM_PATH"
install_registered_shims
remove_stale_shims

2
libexec/jenv-root

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
#!/usr/bin/env bash
echo $JENV_ROOT

32
libexec/jenv-sh-shell

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo --unset
echo system
exec jenv-versions --bare
fi
version="$1"
if [ -z "$version" ]; then
if [ -z "$JENV_VERSION" ]; then
echo "jenv: no shell-specific version configured" >&2
exit 1
else
echo "echo \"\$JENV_VERSION\""
exit
fi
fi
if [ "$version" = "--unset" ]; then
echo "unset JENV_VERSION"
exit 1
fi
# Make sure the specified version is installed.
jenv-prefix "$version" >/dev/null
echo "export JENV_VERSION=\"${version}\""

17
libexec/jenv-shims

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo --short
exit
fi
for command in "${JENV_ROOT}/shims/"*; do
if [ "$1" = "--short" ]; then
echo "${command##*/}"
else
echo "$command"
fi
done | sort

5
libexec/jenv-version

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
echo "$(jenv-version-name) (set by $(jenv-version-origin))"

24
libexec/jenv-version-file

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
root="$JENV_DIR"
while [ -n "$root" ]; do
if [ -e "${root}/.jenv-version" ]; then
echo "${root}/.jenv-version"
exit
fi
root="${root%/*}"
done
global_version_file="${JENV_ROOT}/version"
if [ -e "$global_version_file" ]; then
echo "$global_version_file"
elif [ -e "${JENV_ROOT}/global" ]; then
echo "${JENV_ROOT}/global"
elif [ -e "${JENV_ROOT}/default" ]; then
echo "${JENV_ROOT}/default"
else
echo "$global_version_file"
fi

24
libexec/jenv-version-file-read

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
VERSION_FILE="$1"
if [ -e "$VERSION_FILE" ]; then
# Read and print the first non-whitespace word from the specified
# version file.
version=""
while read -a words; do
word="${words[0]}"
if [ -z "$version" ] && [ -n "$word" ]; then
version="$word"
fi
done < <( cat "$VERSION_FILE" && echo )
if [ -n "$version" ]; then
echo "$version"
exit
fi
fi
exit 1

17
libexec/jenv-version-file-write

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
JENV_VERSION_FILE="$1"
JENV_VERSION="$2"
if [ -z "$JENV_VERSION" ] || [ -z "$JENV_VERSION_FILE" ]; then
echo "usage: jenv write-version-file FILENAME VERSION" >&2
exit 1
fi
# Make sure the specified version is installed.
jenv-prefix "$JENV_VERSION" >/dev/null
# Write the version out to disk.
echo "$JENV_VERSION" > "$JENV_VERSION_FILE"

22
libexec/jenv-version-name

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
if [ -z "$JENV_VERSION" ]; then
JENV_VERSION_FILE="$(jenv-version-file)"
JENV_VERSION="$(jenv-version-file-read "$JENV_VERSION_FILE" || true)"
fi
if [ -z "$JENV_VERSION" ] || [ "$JENV_VERSION" = "system" ]; then
echo "system"
exit
fi
JENV_VERSION_PATH="${JENV_ROOT}/versions/${JENV_VERSION}"
if [ -d "$JENV_VERSION_PATH" ]; then
echo "$JENV_VERSION"
else
echo "jenv: version \`$JENV_VERSION' is not installed" >&2
exit 1
fi

9
libexec/jenv-version-origin

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
if [ -n "$JENV_VERSION" ]; then
echo "JENV_VERSION environment variable"
else
jenv-version-file
fi

27
libexec/jenv-versions

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
JENV_VERSION_NAME="$(jenv-version-name)"
if [ "$1" = "--bare" ]; then
hit_prefix=""
miss_prefix=""
print_version="$JENV_VERSION_NAME"
else
hit_prefix="* "
miss_prefix=" "
print_version="$(jenv-version)"
fi
for path in "${JENV_ROOT}/versions/"*; do
if [ -d "$path" ]; then
version="${path##*/}"
if [ "$version" == "$JENV_VERSION_NAME" ]; then
echo "${hit_prefix}${print_version}"
else
echo "${miss_prefix}${version}"
fi
fi
done

35
libexec/jenv-whence

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo --path
exec jenv shims --short
fi
if [ "$1" = "--path" ]; then
print_paths="1"
shift
else
print_paths=""
fi
whence() {
local command="$1"
jenv-versions --bare | while read version; do
path="$(jenv-prefix "$version")/bin/${command}"
if [ -x "$path" ]; then
[ "$print_paths" ] && echo "$path" || echo "$version"
fi
done
}
JENV_COMMAND="$1"
if [ -z "$JENV_COMMAND" ]; then
echo "usage: jenv whence [--path] COMMAND" >&2
exit 1
fi
result="$(whence "$JENV_COMMAND")"
[ -n "$result" ] && echo "$result"

83
libexec/jenv-which

@ -0,0 +1,83 @@ @@ -0,0 +1,83 @@
#!/usr/bin/env bash
set -e
[ -n "$JENV_DEBUG" ] && set -x
# Provide jenv completions
if [ "$1" = "--complete" ]; then
exec jenv shims --short
fi
expand_path() {
if [ ! -d "$1" ]; then
return 1
fi
local cwd="$(pwd)"
cd "$1"
pwd
cd "$cwd"
}
remove_from_path() {
local path_to_remove="$(expand_path "$1")"
local result=""
if [ -z "$path_to_remove" ]; then
echo "${PATH}"
return
fi
for path in ${PATH//:/$'\n'}; do
path="$(expand_path "$path" || true)"
if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then
result="${result}${path}:"
fi
done
echo "${result%:}"
}
JENV_VERSION="$(jenv-version-name)"
JENV_COMMAND="$1"
if [ -z "$JENV_COMMAND" ]; then
echo "usage: jenv which COMMAND" >&2
exit 1
fi
if [ "$JENV_VERSION" = "system" ]; then
PATH="$(remove_from_path "${JENV_ROOT}/shims")"
JENV_COMMAND_PATH="$(command -v "$JENV_COMMAND")"
else
JENV_COMMAND_PATH="${JENV_ROOT}/versions/${JENV_VERSION}/bin/${JENV_COMMAND}"
if [ -x "$JENV_COMMAND_PATH" ]; then
echo
else
PATH="$(remove_from_path "${JENV_ROOT}/shims")"
JENV_COMMAND_PATH="$(command -v "$JENV_COMMAND")"
fi
fi
for script in $(jenv-hooks which); do
source "$script"
done
if [ -x "$JENV_COMMAND_PATH" ]; then
echo "$JENV_COMMAND_PATH"
else
echo "jenv: $JENV_COMMAND: command not found" >&2
versions="$(jenv-whence "$JENV_COMMAND" || true)"
if [ -n "$versions" ]; then
{ echo
echo "The \`$1' command exists in these Ruby versions:"
echo "$versions" | sed 's/^/ /g'
echo
} >&2
fi
exit 127
fi

2
plugins/maven/etc/jenv.d/rehash/maven.bash

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
bin_path="/usr/share/maven/bin/*"
make_shims "$bin_path"
Loading…
Cancel
Save