From 6e749ef12f41df62fb38d3661f5d665286562c63 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Mon, 30 Sep 2013 18:02:12 +0900 Subject: [PATCH] Import recent changes relating to fish from rbenv --- libexec/pyenv-commands | 27 +++++------- libexec/pyenv-completions | 4 +- libexec/pyenv-fish-shell | 52 ----------------------- libexec/pyenv-help | 6 +-- libexec/pyenv-init | 89 +++++++++++++++++++++++---------------- libexec/pyenv-sh-rehash | 14 +++++- libexec/pyenv-sh-shell | 21 +++++++-- 7 files changed, 99 insertions(+), 114 deletions(-) delete mode 100755 libexec/pyenv-fish-shell diff --git a/libexec/pyenv-commands b/libexec/pyenv-commands index 70f9bcfa..547fd265 100755 --- a/libexec/pyenv-commands +++ b/libexec/pyenv-commands @@ -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 diff --git a/libexec/pyenv-completions b/libexec/pyenv-completions index 385abcc7..9fe54879 100755 --- a/libexec/pyenv-completions +++ b/libexec/pyenv-completions @@ -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 diff --git a/libexec/pyenv-fish-shell b/libexec/pyenv-fish-shell deleted file mode 100755 index 6c4376d4..00000000 --- a/libexec/pyenv-fish-shell +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash -# -# Summary: Set or show the shell-specific Python version -# -# Usage: pyenv shell -# 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. -# -# 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 diff --git a/libexec/pyenv-help b/libexec/pyenv-help index abce46ca..9b7f7e4a 100755 --- a/libexec/pyenv-help +++ b/libexec/pyenv-help @@ -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 } diff --git a/libexec/pyenv-init b/libexec/pyenv-init index 44eb4cfa..25a029b0 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -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 </dev/null $or true" diff --git a/libexec/pyenv-sh-shell b/libexec/pyenv-sh-shell index 245c2687..857359a4 100755 --- a/libexec/pyenv-sh-shell +++ b/libexec/pyenv-sh-shell @@ -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