1
0
mirror of https://github.com/pyenv/pyenv.git synced 2025-11-16 15:23:53 -05:00

add fish shell support

This commit is contained in:
Yamashita Yuu
2013-08-15 23:01:13 +09:00
committed by Mislav Marohnić
parent caa4a8e228
commit 5bfec84432
6 changed files with 129 additions and 15 deletions

View File

@@ -62,6 +62,9 @@ if [ -z "$print" ]; then
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;;
* )
profile='your profile'
;;
@@ -80,7 +83,14 @@ fi
mkdir -p "${RBENV_ROOT}/"{shims,versions}
if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
case "$shell" in
fish )
echo 'setenv PATH "'${RBENV_ROOT}'/shims"' '$PATH' ';'
;;
* )
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
;;
esac
fi
completion="${root}/completions/rbenv.${shell}"
@@ -91,8 +101,27 @@ if [ -z "$no_rehash" ]; then
fi
commands=(`rbenv-commands --sh`)
IFS="|"
cat <<EOS
case "$shell" in
fish )
cat <<EOS
function rbenv
set command \$argv[1]
if [ (count \$argv) -gt 0 ]
set -e argv[1]
end
switch "\$command"
case ${commands[*]}
eval (rbenv "sh-\$command" \$argv)
case '*'
command rbenv "\$command" \$argv
end
end
EOS
;;
* )
IFS="|"
cat <<EOS
rbenv() {
typeset command
command="\$1"
@@ -108,3 +137,5 @@ rbenv() {
esac
}
EOS
;;
esac

View File

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

View File

@@ -24,6 +24,7 @@ if [ "$1" = "--complete" ]; then
fi
version="$1"
shell="$(basename "$SHELL")"
if [ -z "$version" ]; then
if [ -z "$RBENV_VERSION" ]; then
@@ -36,14 +37,28 @@ if [ -z "$version" ]; then
fi
if [ "$version" = "--unset" ]; then
echo "unset RBENV_VERSION"
case "$shell" in
fish )
echo "set -e RBENV_VERSION"
;;
* )
echo "unset RBENV_VERSION"
;;
esac
exit
fi
# Make sure the specified version is installed.
if rbenv-prefix "$version" >/dev/null; then
echo "export RBENV_VERSION=\"${version}\""
case "$shell" in
fish )
echo "setenv RBENV_VERSION \"${version}\""
;;
* )
echo "export RBENV_VERSION=\"${version}\""
;;
esac
else
echo "return 1"
echo "false"
exit 1
fi