Import recent changes relating to fish from rbenv

This commit is contained in:
Yamashita Yuu 2013-09-30 18:02:12 +09:00
parent 850dd87332
commit 6e749ef12f
7 changed files with 99 additions and 114 deletions

View file

@ -8,40 +8,35 @@ set -e
# Provide pyenv completions # Provide pyenv completions
if [ "$1" = "--complete" ]; then if [ "$1" = "--complete" ]; then
echo --sh echo --sh
echo --fish
echo --no-sh echo --no-sh
exit exit
fi fi
if [ "$1" = "--sh" ] || [ "$1" = "--fish" ]; then if [ "$1" = "--sh" ]; then
sh="${1##--}-" sh=1
shift shift
elif [ "$1" = "--no-sh" ] || [ "$1" = "--no-fish" ]; then elif [ "$1" = "--no-sh" ]; then
nosh=1 nosh=1
shift shift
fi fi
IFS=: paths=($PATH)
shopt -s nullglob shopt -s nullglob
{ for path in ${PATH//:/$'\n'}; do { for path in "${paths[@]}"; do
for command in "${path}/pyenv-"*; do for command in "${path}/pyenv-"*; do
command="${command##*pyenv-}" command="${command##*pyenv-}"
if [ -n "$sh" ]; then if [ -n "$sh" ]; then
if [[ "${command}" == "${sh}"* ]]; then if [ ${command:0:3} = "sh-" ]; then
echo "${command##${sh}}" echo ${command##sh-}
fi fi
elif [ -n "$nosh" ]; then elif [ -n "$nosh" ]; then
if [ "${command:0:3}" != "sh-" ] && [ "${command:0:5}" != "fish-" ]; then if [ ${command:0:3} != "sh-" ]; then
echo "$command" echo ${command##sh-}
fi fi
else else
if [ "${command:0:3}" = "sh-" ]; then echo ${command##sh-}
echo "${command##sh-}"
elif [ "${command:0:5}" = "fish-" ]; then
echo "${command##fish-}"
else
echo "${command}"
fi
fi fi
done done
done done

View file

@ -10,8 +10,8 @@ if [ -z "$COMMAND" ]; then
exit 1 exit 1
fi fi
COMMAND_PATH="$(command -v "pyenv-$COMMAND" || command -v "pyenv-sh-$COMMAND" || command -v "pyenv-fish-$COMMAND")" COMMAND_PATH="$(command -v "pyenv-$COMMAND" || command -v "pyenv-sh-$COMMAND")"
if grep -i "^# provide pyenv completions" "$COMMAND_PATH" >/dev/null; then if grep -i "^\([#%]\|--\|//\) provide pyenv completions" "$COMMAND_PATH" >/dev/null; then
shift shift
exec "$COMMAND_PATH" --complete "$@" exec "$COMMAND_PATH" --complete "$@"
fi fi

View file

@ -1,52 +0,0 @@
#!/usr/bin/env bash
#
# Summary: Set or show the shell-specific Python version
#
# Usage: pyenv shell <version>
# pyenv shell --unset
#
# Sets a shell-specific Python version by setting the `PYENV_VERSION'
# environment variable in your shell. This version overrides local
# application-specific versions and the global version.
#
# <version> should be a string matching a Python version known to pyenv.
# The special version string `system' will use your default system Python.
# Run `pyenv versions' for a list of available Python versions.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --unset
echo system
exec pyenv-versions --bare
fi
versions=("$@")
if [ -z "$versions" ]; then
if [ -z "$PYENV_VERSION" ]; then
echo "pyenv: no shell-specific version configured" >&2
exit 1
else
echo "echo \"\$PYENV_VERSION\""
exit
fi
fi
if [ "$versions" = "--unset" ]; then
echo "set -e PYENV_VERSION"
exit
fi
# Make sure the specified version is installed.
if pyenv-prefix "${versions[@]}" >/dev/null; then
OLDIFS="$IFS"
IFS=: PYENV_VERSION="${versions[*]}"
IFS="OLDIFS"
echo "setenv PYENV_VERSION \"${PYENV_VERSION}\""
else
echo "false"
exit 1
fi

View file

@ -17,7 +17,7 @@ set -e
command_path() { command_path() {
local command="$1" local command="$1"
command -v pyenv-"$command" || command -v pyenv-sh-"$command" || command -v pyenv-fish-"$command" || true command -v pyenv-"$command" || command -v pyenv-sh-"$command" || true
} }
extract_initial_comment_block() { extract_initial_comment_block() {
@ -64,8 +64,8 @@ collect_documentation() {
} }
function trim(str) { function trim(str) {
gsub(/^\n*/, "", str) sub(/^\n*/, "", str)
gsub(/\n*$/, "", str) sub(/\n*$/, "", str)
return str return str
} }

View file

@ -11,7 +11,7 @@ for args in "$@"
do do
if [ "$args" = "-" ]; then if [ "$args" = "-" ]; then
print=1 print=1
shift shift
fi fi
if [ "$args" = "--no-rehash" ]; then if [ "$args" = "--no-rehash" ]; then
@ -25,8 +25,14 @@ if [ -z "$shell" ]; then
shell="$(basename "$SHELL")" shell="$(basename "$SHELL")"
fi fi
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
resolve_link() { resolve_link() {
$(type -p greadlink readlink | head -1) $1 $READLINK "$1"
} }
abs_dirname() { abs_dirname() {
@ -67,7 +73,14 @@ if [ -z "$print" ]; then
{ echo "# Load pyenv automatically by adding" { echo "# Load pyenv automatically by adding"
echo "# the following to ${profile}:" echo "# the following to ${profile}:"
echo echo
echo 'eval "$(pyenv init -)"' case "$shell" in
fish )
echo '. (pyenv init -|psub)'
;;
* )
echo 'eval "$(pyenv init -)"'
;;
esac
echo echo
} >&2 } >&2
@ -76,54 +89,58 @@ fi
mkdir -p "${PYENV_ROOT}/"{shims,versions} mkdir -p "${PYENV_ROOT}/"{shims,versions}
case "$shell" in if [[ ":${PATH}:" != *:"${PYENV_ROOT}/shims":* ]]; then
fish ) case "$shell" in
echo 'setenv PATH "'${PYENV_ROOT}'/shims"' '$PATH' ';' fish )
echo "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
;; ;;
* ) * )
echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"' echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
;; ;;
esac esac
fi
case "$shell" in completion="${root}/completions/pyenv.${shell}"
bash | zsh ) [ -r "$completion" ] && echo ". '$completion'"
echo "source \"$root/completions/pyenv.${shell}\""
;;
fish )
echo ". \"$root/completions/pyenv.${shell}\";"
;;
esac
if [ -z "$no_rehash" ]; then if [ -z "$no_rehash" ]; then
echo 'pyenv rehash 2>/dev/null' echo 'pyenv rehash 2>/dev/null'
fi fi
commands=(`pyenv-commands --sh`)
case "$shell" in case "$shell" in
fish ) fish )
commands=(`pyenv-commands --fish`)
cat <<EOS cat <<EOS
;function pyenv; function pyenv
set -e command; set command \$argv[1]
set command \$argv[1]; set -e argv[1]
if [ (count \$argv) -gt 0 ];
set -e argv[1];
end;
switch "\$command"; switch "\$command"
case ${commands[*]}; case ${commands[*]}
eval (pyenv "fish-\$command" \$argv); eval (pyenv "sh-\$command" \$argv)
case '*'; case '*'
command pyenv "\$command" \$argv; command pyenv "\$command" \$argv
end; end
end; end
EOS
exit 0
;;
ksh )
cat <<EOS
function pyenv {
typeset command
EOS EOS
;; ;;
* ) * )
commands=(`pyenv-commands --sh`)
IFS="|"
cat <<EOS cat <<EOS
pyenv() { pyenv() {
typeset command local command
EOS
;;
esac
IFS="|"
cat <<EOS
command="\$1" command="\$1"
if [ "\$#" -gt 0 ]; then if [ "\$#" -gt 0 ]; then
shift shift
@ -131,11 +148,9 @@ pyenv() {
case "\$command" in case "\$command" in
${commands[*]}) ${commands[*]})
eval \`pyenv "sh-\$command" "\$@"\`;; eval "\`pyenv "sh-\$command" "\$@"\`";;
*) *)
command pyenv "\$command" "\$@";; command pyenv "\$command" "\$@";;
esac esac
} }
EOS EOS
;;
esac

View file

@ -7,7 +7,19 @@ if [ "$1" = "--complete" ]; then
exec pyenv-rehash --complete exec pyenv-rehash --complete
fi fi
shell="$(basename "$SHELL")"
# When pyenv shell integration is enabled, delegate to pyenv-rehash, # When pyenv shell integration is enabled, delegate to pyenv-rehash,
# then tell the shell to empty its command lookup cache. # then tell the shell to empty its command lookup cache.
pyenv-rehash pyenv-rehash
echo "hash -r"
case "$shell" in
fish )
or='; or'
;;
* )
or='||'
;;
esac
echo "hash -r 2>/dev/null $or true"

View file

@ -24,6 +24,7 @@ if [ "$1" = "--complete" ]; then
fi fi
versions=("$@") versions=("$@")
shell="$(basename "$SHELL")"
if [ -z "$versions" ]; then if [ -z "$versions" ]; then
if [ -z "$PYENV_VERSION" ]; then if [ -z "$PYENV_VERSION" ]; then
@ -36,7 +37,14 @@ if [ -z "$versions" ]; then
fi fi
if [ "$versions" = "--unset" ]; then if [ "$versions" = "--unset" ]; then
echo "unset PYENV_VERSION" case "$shell" in
fish )
echo "set -e PYENV_VERSION"
;;
* )
echo "unset PYENV_VERSION"
;;
esac
exit exit
fi fi
@ -45,8 +53,15 @@ if pyenv-prefix "${versions[@]}" >/dev/null; then
OLDIFS="$IFS" OLDIFS="$IFS"
IFS=: PYENV_VERSION="${versions[*]}" IFS=: PYENV_VERSION="${versions[*]}"
IFS="$OLDIFS" IFS="$OLDIFS"
echo "export PYENV_VERSION=\"${PYENV_VERSION}\"" case "$shell" in
fish )
echo "setenv PYENV_VERSION \"${PYENV_VERSION}\""
;;
* )
echo "export PYENV_VERSION=\"${PYENV_VERSION}\""
;;
esac
else else
echo "return 1" echo "false"
exit 1 exit 1
fi fi