Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

174 wiersze
2.7 KiB

  1. #!/usr/bin/env bash
  2. # Summary: Configure the shell environment for pyenv
  3. # Usage: eval "$(pyenv init - [--no-rehash] [<shell>])"
  4. set -e
  5. [ -n "$PYENV_DEBUG" ] && set -x
  6. print=""
  7. no_rehash=""
  8. for args in "$@"
  9. do
  10. if [ "$args" = "-" ]; then
  11. print=1
  12. shift
  13. fi
  14. if [ "$args" = "--no-rehash" ]; then
  15. no_rehash=1
  16. shift
  17. fi
  18. done
  19. shell="$1"
  20. if [ -z "$shell" ]; then
  21. shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
  22. shell="${shell##-}"
  23. shell="${shell%% *}"
  24. shell="$(basename "${shell:-$SHELL}")"
  25. fi
  26. READLINK=$(type -p greadlink readlink | head -1)
  27. if [ -z "$READLINK" ]; then
  28. echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
  29. exit 1
  30. fi
  31. resolve_link() {
  32. $READLINK "$1"
  33. }
  34. abs_dirname() {
  35. local cwd="$(pwd)"
  36. local path="$1"
  37. while [ -n "$path" ]; do
  38. cd "${path%/*}"
  39. local name="${path##*/}"
  40. path="$(resolve_link "$name" || true)"
  41. done
  42. pwd
  43. cd "$cwd"
  44. }
  45. root="$(abs_dirname "$0")/.."
  46. if [ -z "$print" ]; then
  47. case "$shell" in
  48. bash )
  49. profile='~/.bash_profile'
  50. ;;
  51. zsh )
  52. profile='~/.zshrc'
  53. ;;
  54. ksh )
  55. profile='~/.profile'
  56. ;;
  57. fish )
  58. profile='~/.config/fish/config.fish'
  59. ;;
  60. * )
  61. profile='your profile'
  62. ;;
  63. esac
  64. { echo "# Load pyenv automatically by adding"
  65. echo "# the following to ${profile}:"
  66. echo
  67. case "$shell" in
  68. fish )
  69. echo 'status --is-interactive; and . (pyenv init -|psub)'
  70. ;;
  71. * )
  72. echo 'eval "$(pyenv init -)"'
  73. ;;
  74. esac
  75. echo
  76. } >&2
  77. exit 1
  78. fi
  79. mkdir -p "${PYENV_ROOT}/"{shims,versions}
  80. if [[ ":${PATH}:" != *:"${PYENV_ROOT}/shims":* ]]; then
  81. case "$shell" in
  82. fish )
  83. echo "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
  84. ;;
  85. * )
  86. echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
  87. ;;
  88. esac
  89. fi
  90. case "$shell" in
  91. fish )
  92. echo "setenv PYENV_SHELL $shell"
  93. ;;
  94. * )
  95. echo "export PYENV_SHELL=$shell"
  96. ;;
  97. esac
  98. completion="${root}/completions/pyenv.${shell}"
  99. if [ -r "$completion" ]; then
  100. case "$shell" in
  101. fish ) echo ". '$completion'" ;;
  102. * ) echo "source '$completion'" ;;
  103. esac
  104. fi
  105. if [ -z "$no_rehash" ]; then
  106. echo 'pyenv rehash 2>/dev/null'
  107. fi
  108. commands=(`pyenv-commands --sh`)
  109. case "$shell" in
  110. fish )
  111. cat <<EOS
  112. function pyenv
  113. set command \$argv[1]
  114. set -e argv[1]
  115. switch "\$command"
  116. case ${commands[*]}
  117. eval (pyenv "sh-\$command" \$argv)
  118. case '*'
  119. command pyenv "\$command" \$argv
  120. end
  121. end
  122. EOS
  123. ;;
  124. ksh )
  125. cat <<EOS
  126. function pyenv {
  127. typeset command
  128. EOS
  129. ;;
  130. * )
  131. cat <<EOS
  132. pyenv() {
  133. local command
  134. EOS
  135. ;;
  136. esac
  137. if [ "$shell" != "fish" ]; then
  138. IFS="|"
  139. cat <<EOS
  140. command="\$1"
  141. if [ "\$#" -gt 0 ]; then
  142. shift
  143. fi
  144. case "\$command" in
  145. ${commands[*]})
  146. eval "\`pyenv "sh-\$command" "\$@"\`";;
  147. *)
  148. command pyenv "\$command" "\$@";;
  149. esac
  150. }
  151. EOS
  152. fi