Merge branch 'improved-fish-support'

This commit is contained in:
Yamashita Yuu 2013-09-30 18:02:54 +09:00
commit c95d446c53
7 changed files with 99 additions and 114 deletions

View file

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

View file

@ -10,8 +10,8 @@ if [ -z "$COMMAND" ]; then
exit 1
fi
COMMAND_PATH="$(command -v "pyenv-$COMMAND" || command -v "pyenv-sh-$COMMAND" || command -v "pyenv-fish-$COMMAND")"
if grep -i "^# provide pyenv completions" "$COMMAND_PATH" >/dev/null; then
COMMAND_PATH="$(command -v "pyenv-$COMMAND" || command -v "pyenv-sh-$COMMAND")"
if grep -i "^\([#%]\|--\|//\) provide pyenv completions" "$COMMAND_PATH" >/dev/null; then
shift
exec "$COMMAND_PATH" --complete "$@"
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() {
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() {
@ -64,8 +64,8 @@ collect_documentation() {
}
function trim(str) {
gsub(/^\n*/, "", str)
gsub(/\n*$/, "", str)
sub(/^\n*/, "", str)
sub(/\n*$/, "", str)
return str
}

View file

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

View file

@ -7,7 +7,19 @@ if [ "$1" = "--complete" ]; then
exec pyenv-rehash --complete
fi
shell="$(basename "$SHELL")"
# When pyenv shell integration is enabled, delegate to pyenv-rehash,
# then tell the shell to empty its command lookup cache.
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
versions=("$@")
shell="$(basename "$SHELL")"
if [ -z "$versions" ]; then
if [ -z "$PYENV_VERSION" ]; then
@ -36,7 +37,14 @@ if [ -z "$versions" ]; then
fi
if [ "$versions" = "--unset" ]; then
echo "unset PYENV_VERSION"
case "$shell" in
fish )
echo "set -e PYENV_VERSION"
;;
* )
echo "unset PYENV_VERSION"
;;
esac
exit
fi
@ -45,8 +53,15 @@ if pyenv-prefix "${versions[@]}" >/dev/null; then
OLDIFS="$IFS"
IFS=: PYENV_VERSION="${versions[*]}"
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
echo "return 1"
echo "false"
exit 1
fi