You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
2.2 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. root="${0%/*}/.."
  27. if [ -z "$print" ]; then
  28. case "$shell" in
  29. bash )
  30. profile='~/.bash_profile'
  31. ;;
  32. zsh )
  33. profile='~/.zshrc'
  34. ;;
  35. ksh )
  36. profile='~/.profile'
  37. ;;
  38. fish )
  39. profile='~/.config/fish/config.fish'
  40. ;;
  41. * )
  42. profile='your profile'
  43. ;;
  44. esac
  45. { echo "# Load pyenv automatically by adding"
  46. echo "# the following to the end of ${profile}:"
  47. echo
  48. case "$shell" in
  49. fish )
  50. echo 'status --is-interactive; and . (pyenv init -|psub)'
  51. ;;
  52. * )
  53. echo 'eval "$(pyenv init -)"'
  54. ;;
  55. esac
  56. echo
  57. } >&2
  58. exit 1
  59. fi
  60. mkdir -p "${PYENV_ROOT}/"{shims,versions}
  61. case "$shell" in
  62. fish )
  63. echo "setenv PATH '${PYENV_ROOT}/shims' \$PATH"
  64. echo "setenv PYENV_SHELL $shell"
  65. ;;
  66. * )
  67. echo 'export PATH="'${PYENV_ROOT}'/shims:${PATH}"'
  68. echo "export PYENV_SHELL=$shell"
  69. ;;
  70. esac
  71. completion="${root}/completions/pyenv.${shell}"
  72. if [ -r "$completion" ]; then
  73. case "$shell" in
  74. fish ) echo ". '$completion'" ;;
  75. * ) echo "source '$completion'" ;;
  76. esac
  77. fi
  78. if [ -z "$no_rehash" ]; then
  79. echo 'pyenv rehash 2>/dev/null'
  80. fi
  81. commands=(`pyenv-commands --sh`)
  82. case "$shell" in
  83. fish )
  84. cat <<EOS
  85. function pyenv
  86. set command \$argv[1]
  87. set -e argv[1]
  88. switch "\$command"
  89. case ${commands[*]}
  90. eval (pyenv "sh-\$command" \$argv)
  91. case '*'
  92. command pyenv "\$command" \$argv
  93. end
  94. end
  95. EOS
  96. ;;
  97. ksh )
  98. cat <<EOS
  99. function pyenv {
  100. typeset command
  101. EOS
  102. ;;
  103. * )
  104. cat <<EOS
  105. pyenv() {
  106. local command
  107. EOS
  108. ;;
  109. esac
  110. if [ "$shell" != "fish" ]; then
  111. IFS="|"
  112. cat <<EOS
  113. command="\$1"
  114. if [ "\$#" -gt 0 ]; then
  115. shift
  116. fi
  117. case "\$command" in
  118. ${commands[*]})
  119. eval "\`pyenv "sh-\$command" "\$@"\`";;
  120. *)
  121. command pyenv "\$command" "\$@";;
  122. esac
  123. }
  124. EOS
  125. fi