Browse Source

Support fish shell

pull/49/head
Yamashita Yuu 11 years ago
parent
commit
93b536863f
7 changed files with 128 additions and 14 deletions
  1. +5
    -0
      completions/pyenv.fish
  2. +15
    -8
      libexec/pyenv-commands
  3. +1
    -1
      libexec/pyenv-completions
  4. +14
    -0
      libexec/pyenv-fish-rehash
  5. +52
    -0
      libexec/pyenv-fish-shell
  6. +1
    -1
      libexec/pyenv-help
  7. +40
    -4
      libexec/pyenv-init

+ 5
- 0
completions/pyenv.fish View File

@ -0,0 +1,5 @@
function __fish_pyenv
pyenv commands
end
complete -f -c pyenv -a '(__fish_pyenv)'

+ 15
- 8
libexec/pyenv-commands View File

@ -8,14 +8,15 @@ 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" ]; then
sh=1
if [ "$1" = "--sh" ] || [ "$1" = "--fish" ]; then
sh="${1##--}-"
shift shift
elif [ "$1" = "--no-sh" ]; then
elif [ "$1" = "--no-sh" ] || [ "$1" = "--no-fish" ]; then
nosh=1 nosh=1
shift shift
fi fi
@ -26,15 +27,21 @@ shopt -s nullglob
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:0:3} = "sh-" ]; then
echo ${command##sh-}
if [[ "${command}" == "${sh}"* ]]; then
echo "${command##${sh}}"
fi fi
elif [ -n "$nosh" ]; then elif [ -n "$nosh" ]; then
if [ ${command:0:3} != "sh-" ]; then
echo ${command##sh-}
if [ "${command:0:3}" != "sh-" ] && [ "${command:0:5}" != "fish-" ]; then
echo "$command"
fi fi
else else
echo ${command##sh-}
if [ "${command:0:3}" = "sh-" ]; then
echo "${command##sh-}"
elif [ "${command:0:5}" = "fish-" ]; then
echo "${command##fish-}"
else
echo "${command}"
fi
fi fi
done done
done done

+ 1
- 1
libexec/pyenv-completions View File

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

+ 14
- 0
libexec/pyenv-fish-rehash View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
exec pyenv-rehash --complete
fi
# When pyenv shell integration is enabled, delegate to pyenv-rehash,
# then tell the shell to empty its command lookup cache.
pyenv-rehash
# FIXME: support fish
#echo "hash -r"

+ 52
- 0
libexec/pyenv-fish-shell View File

@ -0,0 +1,52 @@
#!/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

+ 1
- 1
libexec/pyenv-help 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" || true
command -v pyenv-"$command" || command -v pyenv-sh-"$command" || command -v pyenv-fish-"$command" || true
} }
extract_initial_comment_block() { extract_initial_comment_block() {

+ 40
- 4
libexec/pyenv-init View File

@ -56,6 +56,9 @@ if [ -z "$print" ]; then
ksh ) ksh )
profile='~/.profile' profile='~/.profile'
;; ;;
fish )
profile='~/.config/fish/config.fish'
;;
* ) * )
profile='your profile' profile='your profile'
;; ;;
@ -73,21 +76,52 @@ fi
mkdir -p "${PYENV_ROOT}/"{shims,versions} mkdir -p "${PYENV_ROOT}/"{shims,versions}
echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
case "$shell" in
fish )
echo 'setenv PATH "'${PYENV_ROOT}'/shims"' '$PATH' ';'
;;
* )
echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
;;
esac
case "$shell" in case "$shell" in
bash | zsh ) bash | zsh )
echo "source \"$root/completions/pyenv.${shell}\"" echo "source \"$root/completions/pyenv.${shell}\""
;; ;;
fish )
echo ". \"$root/completions/pyenv.${shell}\";"
;;
esac 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`)
IFS="|"
cat <<EOS
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;
switch "\$command";
case ${commands[*]};
eval (pyenv "fish-\$command" \$argv);
case '*';
command pyenv "\$command" \$argv;
end;
end;
EOS
;;
* )
commands=(`pyenv-commands --sh`)
IFS="|"
cat <<EOS
pyenv() { pyenv() {
typeset command typeset command
command="\$1" command="\$1"
@ -103,3 +137,5 @@ pyenv() {
esac esac
} }
EOS EOS
;;
esac

Loading…
Cancel
Save